From 58149abb7af44ad5340c24b8477eb8eb58e511c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 17:15:10 +0200 Subject: [PATCH 01/70] Enable custom fence with attr_list --- mkdocs.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mkdocs.yml b/mkdocs.yml index caed243a..bf24296c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -22,12 +22,16 @@ markdown_extensions: - name: mermaid class: mermaid-experimental format: !!python/name:pymdownx.superfences.fence_code_format + - name: ponylang + class: ponylang + format: !!python/name:pymdownx.superfences.fence_code_format - pymdownx.snippets: base_path: ['code-samples'] check_paths: true - smarty - toc: permalink: true + - attr_list plugins: - search From 21ff2376a3d7775272386df2e8d5bd22f676fdd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 17:16:34 +0200 Subject: [PATCH 02/70] Modify example --- docs/getting-started/hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/hello-world.md b/docs/getting-started/hello-world.md index 09cdcc1b..fc9e8c50 100644 --- a/docs/getting-started/hello-world.md +++ b/docs/getting-started/hello-world.md @@ -17,7 +17,7 @@ __Does the name of the file matter?__ Not to the compiler, no. Pony doesn't care In your file, put the following code: -```pony +```ponylang snippet="hello-world-main.pony:1-3,5" dedent_subsections=false --8<-- "hello-world-main.pony" ``` From 44f84ad3181a5ac3df27f2c329ae53cbf884f3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 17:54:27 +0200 Subject: [PATCH 03/70] Test --- docs/getting-started/hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/hello-world.md b/docs/getting-started/hello-world.md index fc9e8c50..4e0e8acb 100644 --- a/docs/getting-started/hello-world.md +++ b/docs/getting-started/hello-world.md @@ -17,7 +17,7 @@ __Does the name of the file matter?__ Not to the compiler, no. Pony doesn't care In your file, put the following code: -```ponylang snippet="hello-world-main.pony:1-3,5" dedent_subsections=false +```ponylang snippet="hello-world-main.pony:1-3,6" dedent_subsections=false --8<-- "hello-world-main.pony" ``` From 7dad144c69920311febe7aee804ccf646273a9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:01:45 +0200 Subject: [PATCH 04/70] Ignore wayback machine timeout for now --- mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mkdocs.yml b/mkdocs.yml index bf24296c..c0d0cefe 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -41,6 +41,7 @@ plugins: raise_error_excludes: 429: ["https://github.com/ponylang", "https://web.archive.org/*"] 404: ["https://github.com/ponylang"] + 504: ["https://web.archive.org/*"] theme: name: material From 857800f19f54821ff9f12b904af7adbdca4b88d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:13:07 +0200 Subject: [PATCH 05/70] Add keywords to spellcheck exceptions --- .spelling-wordlist.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.spelling-wordlist.txt b/.spelling-wordlist.txt index 9b45ba8d..1e6c08e1 100644 --- a/.spelling-wordlist.txt +++ b/.spelling-wordlist.txt @@ -10,6 +10,7 @@ booleans capybaras combinators compilable +dedent dereference deserialise deserialised @@ -52,6 +53,7 @@ polymorphism ponyc PonyCheck Ponylang +ponylang PonyTest POSIX preprocessor From f1645184093c9513a955d43c018b1394ae1cb0a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:14:43 +0200 Subject: [PATCH 06/70] use attr_list style code fences --- docs/getting-started/hello-world.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/hello-world.md b/docs/getting-started/hello-world.md index 4e0e8acb..a93b3dc0 100644 --- a/docs/getting-started/hello-world.md +++ b/docs/getting-started/hello-world.md @@ -17,7 +17,7 @@ __Does the name of the file matter?__ Not to the compiler, no. Pony doesn't care In your file, put the following code: -```ponylang snippet="hello-world-main.pony:1-3,6" dedent_subsections=false +```{ .ponylang snippet="hello-world-main.pony:1-3,6" dedent_subsections=false } --8<-- "hello-world-main.pony" ``` From a0ca842c39a31c0e858798cf838444fd64601b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:26:58 +0200 Subject: [PATCH 07/70] Use standard pony syntax highlight --- mkdocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index c0d0cefe..71fc8af9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -23,7 +23,7 @@ markdown_extensions: class: mermaid-experimental format: !!python/name:pymdownx.superfences.fence_code_format - name: ponylang - class: ponylang + class: pony format: !!python/name:pymdownx.superfences.fence_code_format - pymdownx.snippets: base_path: ['code-samples'] From 7a946195c3c57955398d746f0956fa185c2a78ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:33:13 +0200 Subject: [PATCH 08/70] Custom fences formatter and validator --- lib/superfences_ponylang/__init__.py | 5 +++++ mkdocs.yml | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 lib/superfences_ponylang/__init__.py diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py new file mode 100644 index 00000000..2da0e8cb --- /dev/null +++ b/lib/superfences_ponylang/__init__.py @@ -0,0 +1,5 @@ +def custom_formatter(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs): + return '
%s' % (language, class_name, options['opt'], html_escape(source))
+
+def validate(language: str, options: dict) -> bool:
+ return True # TODO allowed attributes and values
\ No newline at end of file
diff --git a/mkdocs.yml b/mkdocs.yml
index 71fc8af9..93f87ac4 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -24,7 +24,8 @@ markdown_extensions:
format: !!python/name:pymdownx.superfences.fence_code_format
- name: ponylang
class: pony
- format: !!python/name:pymdownx.superfences.fence_code_format
+ format: !!python/name:lib.superfences_ponylang.format
+ validator: !!python/name:lib.superfences_ponylang.validate
- pymdownx.snippets:
base_path: ['code-samples']
check_paths: true
From c4a4dca47c331cd31883d2cb6bef6d944ddea7e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 18:34:58 +0200
Subject: [PATCH 09/70] Add module file
---
lib/__init__.py | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 lib/__init__.py
diff --git a/lib/__init__.py b/lib/__init__.py
new file mode 100644
index 00000000..e69de29b
From 25e25d31e1d53ffcb2f651b41b0a35a584e0a7f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 18:44:46 +0200
Subject: [PATCH 10/70] Fix typo
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 2da0e8cb..cf59eff2 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -1,4 +1,4 @@
-def custom_formatter(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
+def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
return '%s' % (language, class_name, options['opt'], html_escape(source))
def validate(language: str, options: dict) -> bool:
From 28952fea1a11e75f344c512116845883848232a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 18:45:16 +0200
Subject: [PATCH 11/70] Use file in route directory (no module)
---
mkdocs.yml | 4 ++--
ponylang_custom_fence.py | 5 +++++
2 files changed, 7 insertions(+), 2 deletions(-)
create mode 100644 ponylang_custom_fence.py
diff --git a/mkdocs.yml b/mkdocs.yml
index 93f87ac4..8779db5a 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -24,8 +24,8 @@ markdown_extensions:
format: !!python/name:pymdownx.superfences.fence_code_format
- name: ponylang
class: pony
- format: !!python/name:lib.superfences_ponylang.format
- validator: !!python/name:lib.superfences_ponylang.validate
+ format: !!python/name:ponylang_custom_fence.format
+ validator: !!python/name:ponylang_custom_fence.validate
- pymdownx.snippets:
base_path: ['code-samples']
check_paths: true
diff --git a/ponylang_custom_fence.py b/ponylang_custom_fence.py
new file mode 100644
index 00000000..cf59eff2
--- /dev/null
+++ b/ponylang_custom_fence.py
@@ -0,0 +1,5 @@
+def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
+ return '%s' % (language, class_name, options['opt'], html_escape(source))
+
+def validate(language: str, options: dict) -> bool:
+ return True # TODO allowed attributes and values
\ No newline at end of file
From bbd94c37ebcb3e39bbc717fc59f4df8e3192aa16 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 19:05:08 +0200
Subject: [PATCH 12/70] Add -m argument to build command
---
netlify.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/netlify.toml b/netlify.toml
index 1b6bb27d..d6665676 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -8,7 +8,7 @@ ID = "Your_Site_ID"
[build]
base = ""
publish = "site/"
- command = "mkdocs build"
+ command = "mkdocs build -m"
[build.environment]
PYTHON_VERSION = "3.8"
From d5ac6d4690be8cb770c55e95b7cbd0fc72fe5144 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 19:44:35 +0200
Subject: [PATCH 13/70] load local modules
---
mkdocs.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mkdocs.yml b/mkdocs.yml
index 8779db5a..93f87ac4 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -24,8 +24,8 @@ markdown_extensions:
format: !!python/name:pymdownx.superfences.fence_code_format
- name: ponylang
class: pony
- format: !!python/name:ponylang_custom_fence.format
- validator: !!python/name:ponylang_custom_fence.validate
+ format: !!python/name:lib.superfences_ponylang.format
+ validator: !!python/name:lib.superfences_ponylang.validate
- pymdownx.snippets:
base_path: ['code-samples']
check_paths: true
From f669393e155078a76cde77790383021588000f37 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 19:44:41 +0200
Subject: [PATCH 14/70] reqs
---
requirements.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/requirements.txt b/requirements.txt
index 070ed359..607a60c9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,4 @@
git+https://${INSIDERS_PAT}@github.com/squidfunk/mkdocs-material-insiders.git
mkdocs-htmlproofer-plugin>=0.1.0
-mkdocs-ezlinks-plugin>=0.1.8
\ No newline at end of file
+mkdocs-ezlinks-plugin>=0.1.8
+--find-links=lib
\ No newline at end of file
From eca6abfa7315106358c034e9a385fff5904d9bda Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 19:47:01 +0200
Subject: [PATCH 15/70] Remove unrecognized option from build command
---
netlify.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/netlify.toml b/netlify.toml
index d6665676..1b6bb27d 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -8,7 +8,7 @@ ID = "Your_Site_ID"
[build]
base = ""
publish = "site/"
- command = "mkdocs build -m"
+ command = "mkdocs build"
[build.environment]
PYTHON_VERSION = "3.8"
From 88b96d58f4f07a03a7c4cea856b234903fe2fc81 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 19:52:56 +0200
Subject: [PATCH 16/70] Install lib module folder as part of build command
---
netlify.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/netlify.toml b/netlify.toml
index 1b6bb27d..73c68a8c 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -8,7 +8,7 @@ ID = "Your_Site_ID"
[build]
base = ""
publish = "site/"
- command = "mkdocs build"
+ command = "pip install --no-index --find-links lib && mkdocs build"
[build.environment]
PYTHON_VERSION = "3.8"
From fee9326ad7022776ad59311f43c18a44267cc482 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 19:54:55 +0200
Subject: [PATCH 17/70] requirements in install command
---
netlify.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/netlify.toml b/netlify.toml
index 73c68a8c..07971a53 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -8,7 +8,7 @@ ID = "Your_Site_ID"
[build]
base = ""
publish = "site/"
- command = "pip install --no-index --find-links lib && mkdocs build"
+ command = "pip install -r requirements.txt --find-links lib && mkdocs build"
[build.environment]
PYTHON_VERSION = "3.8"
From b20f323700cc0e5299d84166e6113ffd336da31f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 20:00:36 +0200
Subject: [PATCH 18/70] PYTHONPATH in build command
---
netlify.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/netlify.toml b/netlify.toml
index 07971a53..ac671ccc 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -8,7 +8,7 @@ ID = "Your_Site_ID"
[build]
base = ""
publish = "site/"
- command = "pip install -r requirements.txt --find-links lib && mkdocs build"
+ command = "export PYTHONPATH=$PYTHONPATH:`pwd` && mkdocs build"
[build.environment]
PYTHON_VERSION = "3.8"
From 1cea0d7f39f8afac8b616ac236ce4689dca56784 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 20:06:33 +0200
Subject: [PATCH 19/70] Remove redundant
---
requirements.txt | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/requirements.txt b/requirements.txt
index 607a60c9..070ed359 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,3 @@
git+https://${INSIDERS_PAT}@github.com/squidfunk/mkdocs-material-insiders.git
mkdocs-htmlproofer-plugin>=0.1.0
-mkdocs-ezlinks-plugin>=0.1.8
---find-links=lib
\ No newline at end of file
+mkdocs-ezlinks-plugin>=0.1.8
\ No newline at end of file
From 4cceaa5de6d9297e191ce57afd80cf1e99ac0bfa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 20:06:44 +0200
Subject: [PATCH 20/70] static class
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index cf59eff2..06c73ffa 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -1,5 +1,5 @@
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
- return '%s' % (language, class_name, options['opt'], html_escape(source))
+ return '%s' % (language, class_name, options['opt'], html_escape(source))
def validate(language: str, options: dict) -> bool:
return True # TODO allowed attributes and values
\ No newline at end of file
From c34ae9db16ab4c73c47dc067d8251e3d2ab4790c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 20:11:57 +0200
Subject: [PATCH 21/70] Add validation
---
lib/superfences_ponylang/__init__.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 06c73ffa..8689c5a2 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -2,4 +2,8 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
return '%s' % (language, class_name, options['opt'], html_escape(source))
def validate(language: str, options: dict) -> bool:
- return True # TODO allowed attributes and values
\ No newline at end of file
+ allowed_options = { "snippet", "dedent_subsections" } #lambda v: v in ENGINES
+ for opt in options.keys():
+ if opt not in allowed_options:
+ return False
+ return True
\ No newline at end of file
From 0ac65f12fdf893f4d872e45ed157084f3a5e0dd2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 20:19:41 +0200
Subject: [PATCH 22/70] use pygments
---
lib/superfences_ponylang/__init__.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 8689c5a2..04f8f741 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -1,5 +1,16 @@
+from pygments import highlight
+from pygments.lexers import PythonLexer
+from pygments.formatters import HtmlFormatter
+
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
- return '%s' % (language, class_name, options['opt'], html_escape(source))
+ return """
+
+
+ %s
+
+ """ % (language, class_name, options['opt'], html_escape(highlight(source, PythonLexer(), HtmlFormatter())))
def validate(language: str, options: dict) -> bool:
allowed_options = { "snippet", "dedent_subsections" } #lambda v: v in ENGINES
From ad2376280fc1b434823005f847039c319d26d1c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 20:21:31 +0200
Subject: [PATCH 23/70] Add nav buttons
---
lib/superfences_ponylang/__init__.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 04f8f741..05d0513b 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -7,6 +7,8 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
%s
From c5ce12a7c0a3cff4a487c10d613ec743f4f0fd55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 20:23:50 +0200
Subject: [PATCH 24/70] debug
---
lib/superfences_ponylang/__init__.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 05d0513b..8319e891 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -3,6 +3,7 @@
from pygments.formatters import HtmlFormatter
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
+ print(highlight(source, PythonLexer(), HtmlFormatter()))
return """
""" % (language, class_name, options['opt'], html_escape(highlighted))
-def validate(language: str, options: dict) -> bool:
+def validate(language: str, options: dict, attrs: dict, md) -> bool:
return True
allowed_options = { "snippet", "dedent_subsections" } #lambda v: v in ENGINES
for opt in options.keys():
From efd8ff09edb458fe6c08f3a57bc0247f7bdc4ab0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 23:09:34 +0200
Subject: [PATCH 29/70] Imports
---
lib/superfences_ponylang/__init__.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index d0cdc540..c8042d9d 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -2,6 +2,11 @@
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
+from pymdownx.superfences import SuperFencesException
+from pymdownx.superfences import _escape
+
+from mkdocs.exceptions import PluginError
+
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
return "Hello world"
try:
@@ -18,7 +23,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
%s
- """ % (language, class_name, options['opt'], html_escape(highlighted))
+ """ % (language, class_name, options['opt'], _escape(highlighted)) # html_escape
def validate(language: str, options: dict, attrs: dict, md) -> bool:
return True
From 540b3b09fe70ac055dfef0acb2660b25b8ab4ab9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 23:16:49 +0200
Subject: [PATCH 30/70] Don't validate
---
mkdocs.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mkdocs.yml b/mkdocs.yml
index 93f87ac4..ef6a0c7c 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -25,7 +25,7 @@ markdown_extensions:
- name: ponylang
class: pony
format: !!python/name:lib.superfences_ponylang.format
- validator: !!python/name:lib.superfences_ponylang.validate
+ #validator: !!python/name:lib.superfences_ponylang.validate
- pymdownx.snippets:
base_path: ['code-samples']
check_paths: true
From baa2d95005964503c10453c95ce2026b16fd5452 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 23:18:35 +0200
Subject: [PATCH 31/70] Return actual markup
---
lib/superfences_ponylang/__init__.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index c8042d9d..22d162ba 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -8,7 +8,6 @@
from mkdocs.exceptions import PluginError
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
- return "Hello world"
try:
highlighted = highlight(source, PythonLexer(), HtmlFormatter())
except:
From 98bcee479944f39d0bbe814ccdadaadb3d757a1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 23:26:29 +0200
Subject: [PATCH 32/70] return markup directly
---
lib/superfences_ponylang/__init__.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 22d162ba..90a07693 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -13,6 +13,8 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
except:
raise SuperFencesException('Could not highlight source code "%s" passed' % (source))
+ return highlighted
+
return """
From 8a78fcb118650bdbbe7f8f89d774669d10d02f04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 23:31:14 +0200
Subject: [PATCH 33/70] Use pony lexer
---
lib/superfences_ponylang/__init__.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 90a07693..334aa5d2 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -1,5 +1,5 @@
from pygments import highlight
-from pygments.lexers import PythonLexer
+from pygments.lexers import PonyLexer
from pygments.formatters import HtmlFormatter
from pymdownx.superfences import SuperFencesException
@@ -9,7 +9,7 @@
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
try:
- highlighted = highlight(source, PythonLexer(), HtmlFormatter())
+ highlighted = highlight(source, PonyLexer(), HtmlFormatter())
except:
raise SuperFencesException('Could not highlight source code "%s" passed' % (source))
From 97204f38aee58b0f25b8ad6034ba8f176a27d399 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 23:40:34 +0200
Subject: [PATCH 34/70] Load snippet
---
docs/getting-started/hello-world.md | 2 +-
lib/superfences_ponylang/__init__.py | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/docs/getting-started/hello-world.md b/docs/getting-started/hello-world.md
index a93b3dc0..33afa63f 100644
--- a/docs/getting-started/hello-world.md
+++ b/docs/getting-started/hello-world.md
@@ -18,7 +18,7 @@ __Does the name of the file matter?__ Not to the compiler, no. Pony doesn't care
In your file, put the following code:
```{ .ponylang snippet="hello-world-main.pony:1-3,6" dedent_subsections=false }
---8<-- "hello-world-main.pony"
+Gibberish
```
## Compiling the program
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 334aa5d2..7668bbd5 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -8,6 +8,14 @@
from mkdocs.exceptions import PluginError
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
+ if "snippet" in options:
+ snippetPath = options.get(snippet)
+ if ':' in snippetPath:
+ snippetPath, lines = snippetPath.split(':', 2)
+
+ with open(snippetPath, 'r') as f:
+ source = f.read()
+
try:
highlighted = highlight(source, PonyLexer(), HtmlFormatter())
except:
From 3f66f5118a49a2fe5bf8edb75d9f0047844a1163 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 23:47:01 +0200
Subject: [PATCH 35/70] debug
---
lib/superfences_ponylang/__init__.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 7668bbd5..40cf5aab 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -15,6 +15,8 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
with open(snippetPath, 'r') as f:
source = f.read()
+ else:
+ source = str(options)
try:
highlighted = highlight(source, PonyLexer(), HtmlFormatter())
From 09e035a3e56f1acc8624e2681609d5113883a3e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Wed, 5 Jun 2024 23:49:56 +0200
Subject: [PATCH 36/70] debug all dicts
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 40cf5aab..a6ac039d 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -16,7 +16,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
with open(snippetPath, 'r') as f:
source = f.read()
else:
- source = str(options)
+ source = str(options) + str(attrs) + str(classes) + str(kwargs)
try:
highlighted = highlight(source, PonyLexer(), HtmlFormatter())
From 8dc6ee7a611b0968ed1df06c6b7aacc5155a3c02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:07:45 +0200
Subject: [PATCH 37/70] get snippet lines
---
lib/superfences_ponylang/__init__.py | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index a6ac039d..8aef62aa 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -8,13 +8,29 @@
from mkdocs.exceptions import PluginError
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
- if "snippet" in options:
- snippetPath = options.get(snippet)
+ if "snippet" in attrs: #options
+ snippetPath = attrs.get(snippet)
if ':' in snippetPath:
- snippetPath, lines = snippetPath.split(':', 2)
-
- with open(snippetPath, 'r') as f:
- source = f.read()
+ snippetPath, lineNumbers = snippetPath.split(':', 2)
+ lines = []
+ if ',' in lineNumbers:
+ lineNumbers = lineNumbers.split(',')
+ else:
+ lineNumbers = [ lineNumbers ]
+ with open(snippetPath, 'r') as f:
+ for i, line in enumerate(f):
+ for lineNum in enumerate(lineNumbers):
+ if '-' in lineNum:
+ start, end = lineNum.split('-')
+ if i > start and i < end:
+ lines.append(line)
+ elif i == lineNum:
+ lines.append(line)
+ source = '\n'.join(lines)
+
+ else:
+ with open(snippetPath, 'r') as f:
+ source = f.read()
else:
source = str(options) + str(attrs) + str(classes) + str(kwargs)
From 17c928171c97374a4b154880391006810cdd7557 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:11:40 +0200
Subject: [PATCH 38/70] Simplify
---
docs/getting-started/hello-world.md | 2 +-
docs/getting-started/how-it-works.md | 4 +--
lib/superfences_ponylang/__init__.py | 41 ++++++++++++++--------------
3 files changed, 23 insertions(+), 24 deletions(-)
diff --git a/docs/getting-started/hello-world.md b/docs/getting-started/hello-world.md
index 33afa63f..526e01bc 100644
--- a/docs/getting-started/hello-world.md
+++ b/docs/getting-started/hello-world.md
@@ -17,7 +17,7 @@ __Does the name of the file matter?__ Not to the compiler, no. Pony doesn't care
In your file, put the following code:
-```{ .ponylang snippet="hello-world-main.pony:1-3,6" dedent_subsections=false }
+```{ .ponylang snippet="hello-world-main.pony" dedent_subsections=false }
Gibberish
```
diff --git a/docs/getting-started/how-it-works.md b/docs/getting-started/how-it-works.md
index 5f0c069c..7508759c 100644
--- a/docs/getting-started/how-it-works.md
+++ b/docs/getting-started/how-it-works.md
@@ -10,8 +10,8 @@ Let's go through that line by line.
## Line 1
-```pony
---8<-- "hello-world-main.pony::1"
+```{ .ponylang snippet="hello-world-main.pony:1-3,6" dedent_subsections=false }
+Lorem ipsum
```
This is a __type declaration__. The keyword `actor` means we are going to define an actor, which is a bit like a class in Python, Java, C#, C++, etc. Pony has classes too, which we'll see later.
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 8aef62aa..c9f0a50d 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -10,27 +10,26 @@
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
if "snippet" in attrs: #options
snippetPath = attrs.get(snippet)
- if ':' in snippetPath:
- snippetPath, lineNumbers = snippetPath.split(':', 2)
- lines = []
- if ',' in lineNumbers:
- lineNumbers = lineNumbers.split(',')
- else:
- lineNumbers = [ lineNumbers ]
- with open(snippetPath, 'r') as f:
- for i, line in enumerate(f):
- for lineNum in enumerate(lineNumbers):
- if '-' in lineNum:
- start, end = lineNum.split('-')
- if i > start and i < end:
- lines.append(line)
- elif i == lineNum:
- lines.append(line)
- source = '\n'.join(lines)
-
- else:
- with open(snippetPath, 'r') as f:
- source = f.read()
+ #if ':' in snippetPath:
+ # snippetPath, lineNumbers = snippetPath.split(':', 2)
+ # lines = []
+ # if ',' in lineNumbers:
+ # lineNumbers = lineNumbers.split(',')
+ # else:
+ # lineNumbers = [ lineNumbers ]
+ # with open(snippetPath, 'r') as f:
+ # for i, line in enumerate(f):
+ # for lineNum in enumerate(lineNumbers):
+ # if '-' in lineNum:
+ # start, end = lineNum.split('-')
+ # if i > start and i < end:
+ # lines.append(line)
+ # elif i == lineNum:
+ # lines.append(line)
+ # source = '\n'.join(lines)
+ #else:
+ with open(snippetPath, 'r') as f:
+ source = f.read()
else:
source = str(options) + str(attrs) + str(classes) + str(kwargs)
From 5bfad84002e96fd50173ec3ba3fbcee6a8bd270f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:14:51 +0200
Subject: [PATCH 39/70] Fix key as string
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index c9f0a50d..e7643da5 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -9,7 +9,7 @@
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
if "snippet" in attrs: #options
- snippetPath = attrs.get(snippet)
+ snippetPath = attrs.get('snippet')
#if ':' in snippetPath:
# snippetPath, lineNumbers = snippetPath.split(':', 2)
# lines = []
From 706ca165dcfd0496d5696aaea4b7277ab82970a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:18:37 +0200
Subject: [PATCH 40/70] try-catch
---
lib/superfences_ponylang/__init__.py | 45 +++++++++++++++-------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index e7643da5..f153fd84 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -9,27 +9,30 @@
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
if "snippet" in attrs: #options
- snippetPath = attrs.get('snippet')
- #if ':' in snippetPath:
- # snippetPath, lineNumbers = snippetPath.split(':', 2)
- # lines = []
- # if ',' in lineNumbers:
- # lineNumbers = lineNumbers.split(',')
- # else:
- # lineNumbers = [ lineNumbers ]
- # with open(snippetPath, 'r') as f:
- # for i, line in enumerate(f):
- # for lineNum in enumerate(lineNumbers):
- # if '-' in lineNum:
- # start, end = lineNum.split('-')
- # if i > start and i < end:
- # lines.append(line)
- # elif i == lineNum:
- # lines.append(line)
- # source = '\n'.join(lines)
- #else:
- with open(snippetPath, 'r') as f:
- source = f.read()
+ try:
+ snippetPath = attrs.get('snippet')
+ #if ':' in snippetPath:
+ # snippetPath, lineNumbers = snippetPath.split(':', 2)
+ # lines = []
+ # if ',' in lineNumbers:
+ # lineNumbers = lineNumbers.split(',')
+ # else:
+ # lineNumbers = [ lineNumbers ]
+ # with open(snippetPath, 'r') as f:
+ # for i, line in enumerate(f):
+ # for lineNum in enumerate(lineNumbers):
+ # if '-' in lineNum:
+ # start, end = lineNum.split('-')
+ # if i > start and i < end:
+ # lines.append(line)
+ # elif i == lineNum:
+ # lines.append(line)
+ # source = '\n'.join(lines)
+ #else:
+ with open(snippetPath, 'r') as f:
+ source = f.read()
+ except:
+ raise SuperFencesException('Snippet "%s" does not work' % (source))
else:
source = str(options) + str(attrs) + str(classes) + str(kwargs)
From 7f67cc45d3c40ff5c6a69903070e6e29dec093b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:21:23 +0200
Subject: [PATCH 41/70] Fix file path
---
lib/superfences_ponylang/__init__.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index f153fd84..0534052d 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -18,7 +18,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
# lineNumbers = lineNumbers.split(',')
# else:
# lineNumbers = [ lineNumbers ]
- # with open(snippetPath, 'r') as f:
+ # with open("code-samples/" + snippetPath, 'r') as f:
# for i, line in enumerate(f):
# for lineNum in enumerate(lineNumbers):
# if '-' in lineNum:
@@ -29,7 +29,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
# lines.append(line)
# source = '\n'.join(lines)
#else:
- with open(snippetPath, 'r') as f:
+ with open("code-samples/" + snippetPath, 'r') as f:
source = f.read()
except:
raise SuperFencesException('Snippet "%s" does not work' % (source))
From cfd7773dab3edd74715044bf444b93a5a6601814 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:29:19 +0200
Subject: [PATCH 42/70] use cwd
---
lib/superfences_ponylang/__init__.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 0534052d..eefc8c1a 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -18,7 +18,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
# lineNumbers = lineNumbers.split(',')
# else:
# lineNumbers = [ lineNumbers ]
- # with open("code-samples/" + snippetPath, 'r') as f:
+ # with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
# for i, line in enumerate(f):
# for lineNum in enumerate(lineNumbers):
# if '-' in lineNum:
@@ -29,10 +29,10 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
# lines.append(line)
# source = '\n'.join(lines)
#else:
- with open("code-samples/" + snippetPath, 'r') as f:
+ with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
except:
- raise SuperFencesException('Snippet "%s" does not work' % (source))
+ raise SuperFencesException('Snippet "%s" does not work' % (snippetPath))
else:
source = str(options) + str(attrs) + str(classes) + str(kwargs)
From a864c1ea74f9a98b0bf3dffcdb83ac4defe814e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:43:45 +0200
Subject: [PATCH 43/70] Add import
---
lib/superfences_ponylang/__init__.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index eefc8c1a..38a30445 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -7,8 +7,11 @@
from mkdocs.exceptions import PluginError
+import os
+
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
if "snippet" in attrs: #options
+ #workingDir = os.getcwd().replace('/lib/superfences_ponylang')
try:
snippetPath = attrs.get('snippet')
#if ':' in snippetPath:
From 7110b2fb3374125bef02b0337c7adaf4421d71d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:46:48 +0200
Subject: [PATCH 44/70] re-implement line number logic
---
lib/superfences_ponylang/__init__.py | 40 ++++++++++++++--------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 38a30445..ad45174b 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -14,26 +14,26 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
#workingDir = os.getcwd().replace('/lib/superfences_ponylang')
try:
snippetPath = attrs.get('snippet')
- #if ':' in snippetPath:
- # snippetPath, lineNumbers = snippetPath.split(':', 2)
- # lines = []
- # if ',' in lineNumbers:
- # lineNumbers = lineNumbers.split(',')
- # else:
- # lineNumbers = [ lineNumbers ]
- # with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
- # for i, line in enumerate(f):
- # for lineNum in enumerate(lineNumbers):
- # if '-' in lineNum:
- # start, end = lineNum.split('-')
- # if i > start and i < end:
- # lines.append(line)
- # elif i == lineNum:
- # lines.append(line)
- # source = '\n'.join(lines)
- #else:
- with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
- source = f.read()
+ if ':' in snippetPath:
+ snippetPath, lineNumbers = snippetPath.split(':', 2)
+ lines = []
+ if ',' in lineNumbers:
+ lineNumbers = lineNumbers.split(',')
+ else:
+ lineNumbers = [ lineNumbers ]
+ with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
+ for i, line in enumerate(f):
+ for lineNum in enumerate(lineNumbers):
+ if '-' in lineNum:
+ start, end = lineNum.split('-')
+ if i > start and i < end:
+ lines.append(line)
+ elif i == lineNum:
+ lines.append(line)
+ source = '\n'.join(lines)
+ else:
+ with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
+ source = f.read()
except:
raise SuperFencesException('Snippet "%s" does not work' % (snippetPath))
else:
From eccd56764040cb9bebc0358097cb113c311c419a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:49:17 +0200
Subject: [PATCH 45/70] debug again
---
lib/superfences_ponylang/__init__.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index ad45174b..f5e9d4af 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -30,7 +30,8 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
lines.append(line)
elif i == lineNum:
lines.append(line)
- source = '\n'.join(lines)
+ source = str(lines)
+ #source = '\n'.join(lines)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
From d5d775cee417d3ea145c52a36ffb477a8d96f241 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:51:42 +0200
Subject: [PATCH 46/70] convert to number
---
lib/superfences_ponylang/__init__.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index f5e9d4af..92151c3d 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -26,9 +26,9 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
for lineNum in enumerate(lineNumbers):
if '-' in lineNum:
start, end = lineNum.split('-')
- if i > start and i < end:
+ if i > int(start) and i < int(end):
lines.append(line)
- elif i == lineNum:
+ elif i == int(lineNum):
lines.append(line)
source = str(lines)
#source = '\n'.join(lines)
From fadf122e9e9fe58a0e559041b9e4ad8dd0c9dd02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:53:59 +0200
Subject: [PATCH 47/70] destructure tuple
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 92151c3d..3ada56fe 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -23,7 +23,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
lineNumbers = [ lineNumbers ]
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
for i, line in enumerate(f):
- for lineNum in enumerate(lineNumbers):
+ for _, lineNum in enumerate(lineNumbers):
if '-' in lineNum:
start, end = lineNum.split('-')
if i > int(start) and i < int(end):
From e9476e76d9eb0922ff037c96733bd00cc02bf317 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:56:04 +0200
Subject: [PATCH 48/70] inclusive comparison
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 3ada56fe..dea3fa88 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -26,7 +26,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
for _, lineNum in enumerate(lineNumbers):
if '-' in lineNum:
start, end = lineNum.split('-')
- if i > int(start) and i < int(end):
+ if i >= int(start) and i <= int(end):
lines.append(line)
elif i == int(lineNum):
lines.append(line)
From 06d8926d541164122ad60bee3b4d4e31967d7e89 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 00:56:16 +0200
Subject: [PATCH 49/70] re-implement line join
---
lib/superfences_ponylang/__init__.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index dea3fa88..a9e5a5d3 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -30,8 +30,8 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
lines.append(line)
elif i == int(lineNum):
lines.append(line)
- source = str(lines)
- #source = '\n'.join(lines)
+ #source = str(lines)
+ source = '\n'.join(lines)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
From 4a55e865f6731a6cf93f1bba2681bdf7ffcbc549 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 01:10:27 +0200
Subject: [PATCH 50/70] Simplify
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index a9e5a5d3..9a929c2f 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -23,7 +23,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
lineNumbers = [ lineNumbers ]
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
for i, line in enumerate(f):
- for _, lineNum in enumerate(lineNumbers):
+ for lineNum in lineNumbers:
if '-' in lineNum:
start, end = lineNum.split('-')
if i >= int(start) and i <= int(end):
From 5410c2bd25fc6256ffe273b65b34880ab6863bcb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 01:16:58 +0200
Subject: [PATCH 51/70] debug
---
lib/superfences_ponylang/__init__.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 9a929c2f..d978de41 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -31,7 +31,8 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
elif i == int(lineNum):
lines.append(line)
#source = str(lines)
- source = '\n'.join(lines)
+ source = '\n'.join(lines)
+ source = str(md) + str(options) + str(attrs) + str(classes) + str(kwargs)#.registeredExtensions.
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
From 505d1f550276cf7cd51e9419e286eae582409b15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 01:22:31 +0200
Subject: [PATCH 52/70] split class in debugging
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index d978de41..d9ac4021 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -32,7 +32,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
lines.append(line)
#source = str(lines)
source = '\n'.join(lines)
- source = str(md) + str(options) + str(attrs) + str(classes) + str(kwargs)#.registeredExtensions.
+ source = str(md.preprocessors) + str(md.parser) + str(md.registeredExtensions) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
From b1e9d7fac8bc6aecc34d17a8bbc8620c911de75f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 01:36:55 +0200
Subject: [PATCH 53/70] config
---
lib/superfences_ponylang/__init__.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index d9ac4021..05262afb 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -6,6 +6,10 @@
from pymdownx.superfences import _escape
from mkdocs.exceptions import PluginError
+from mkdocs.config import base
+from mkdocs.config import config_options as c
+from mkdocs.structure.pages import Page, _AbsoluteLinksValidationValue
+from mkdocs.utils.yaml import get_yaml_loader, yaml_load
import os
@@ -32,7 +36,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
lines.append(line)
#source = str(lines)
source = '\n'.join(lines)
- source = str(md.preprocessors) + str(md.parser) + str(md.registeredExtensions) + str(options) + str(attrs) + str(classes) + str(kwargs)
+ source = str(base.Config) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
From 91ba8c3f0dfe7691d672747ba1dc5b938622339c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 01:43:47 +0200
Subject: [PATCH 54/70] debug
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 05262afb..204bb5ea 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -36,7 +36,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
lines.append(line)
#source = str(lines)
source = '\n'.join(lines)
- source = str(base.Config) + str(options) + str(attrs) + str(classes) + str(kwargs)
+ source = str(base.Config.__dict__) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
From d3bbcd1a1f51925441a8a1b91bc8b1448cfadc6a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 01:49:46 +0200
Subject: [PATCH 55/70] more debug
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 204bb5ea..b80877e3 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -36,7 +36,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
lines.append(line)
#source = str(lines)
source = '\n'.join(lines)
- source = str(base.Config.__dict__) + str(options) + str(attrs) + str(classes) + str(kwargs)
+ source = str(base.Config.user_configs.__dict__) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
From b113123ea24f0076e09ceefb726b573a67b14307 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 01:59:06 +0200
Subject: [PATCH 56/70] even more debug
---
lib/superfences_ponylang/__init__.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index b80877e3..f0663036 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -10,6 +10,7 @@
from mkdocs.config import config_options as c
from mkdocs.structure.pages import Page, _AbsoluteLinksValidationValue
from mkdocs.utils.yaml import get_yaml_loader, yaml_load
+from mkdocs.utils.templates import TemplateContext
import os
@@ -36,7 +37,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
lines.append(line)
#source = str(lines)
source = '\n'.join(lines)
- source = str(base.Config.user_configs.__dict__) + str(options) + str(attrs) + str(classes) + str(kwargs)
+ source = str(base.Config.user_configs.__dict__) + str(TemplateContext) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
From 54918e258be49c5ca4a570a393a1615023d6b5a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 02:01:17 +0200
Subject: [PATCH 57/70] debug - why not?
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index f0663036..e12f92d5 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -37,7 +37,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
lines.append(line)
#source = str(lines)
source = '\n'.join(lines)
- source = str(base.Config.user_configs.__dict__) + str(TemplateContext) + str(options) + str(attrs) + str(classes) + str(kwargs)
+ source = str(base.Config.user_configs.__dict__) + str(TemplateContext) + str(c) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
From de5fc304be7bacafec3658192b3eb6f2126272df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 02:33:15 +0200
Subject: [PATCH 58/70] dedent_subsections logic
---
lib/superfences_ponylang/__init__.py | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index e12f92d5..4d79b4b1 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -13,6 +13,7 @@
from mkdocs.utils.templates import TemplateContext
import os
+import re
def format(source, language, css_class, options, md, classes=None, id_value='', attrs=None, **kwargs):
if "snippet" in attrs: #options
@@ -36,8 +37,23 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
elif i == int(lineNum):
lines.append(line)
#source = str(lines)
+
+ if 'dedent_subsections' in attrs and attrs.get('dedent_subsections'):
+ p = re.compile('^\s+')
+ indents = []
+ for line in lines:
+ m = p.match(line)
+ if m is None:
+ indents.append(0)
+ else:
+ indents.append(m.span()[1])
+ indent = min(indents)
+ if indent > 0:
+ for i, line in enumerate(lines):
+ lines[i] = line[indent:None]
+
source = '\n'.join(lines)
- source = str(base.Config.user_configs.__dict__) + str(TemplateContext) + str(c) + str(options) + str(attrs) + str(classes) + str(kwargs)
+ #source = str(base.Config.user_configs.__dict__) + str(TemplateContext) + str(c) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
source = f.read()
From b1b788dfdfe13b618258c6bebfd8a65d4590e079 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 02:39:29 +0200
Subject: [PATCH 59/70] debug once again
---
lib/superfences_ponylang/__init__.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 4d79b4b1..9d6f13f4 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -23,6 +23,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
if ':' in snippetPath:
snippetPath, lineNumbers = snippetPath.split(':', 2)
lines = []
+ _lines = {}
if ',' in lineNumbers:
lineNumbers = lineNumbers.split(',')
else:
@@ -34,9 +35,12 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
start, end = lineNum.split('-')
if i >= int(start) and i <= int(end):
lines.append(line)
+ _lines[i] = (lineNumbers, line)
elif i == int(lineNum):
lines.append(line)
+ _lines[i] = (lineNumbers, line)
#source = str(lines)
+ source = str(_lines)
if 'dedent_subsections' in attrs and attrs.get('dedent_subsections'):
p = re.compile('^\s+')
@@ -52,7 +56,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
for i, line in enumerate(lines):
lines[i] = line[indent:None]
- source = '\n'.join(lines)
+ #source = '\n'.join(lines)
#source = str(base.Config.user_configs.__dict__) + str(TemplateContext) + str(c) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
From ceb55109672fac5714f894728722f794b5a4e82f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 02:42:59 +0200
Subject: [PATCH 60/70] 1-indexed
---
lib/superfences_ponylang/__init__.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 9d6f13f4..4adc2c74 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -33,12 +33,14 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
for lineNum in lineNumbers:
if '-' in lineNum:
start, end = lineNum.split('-')
- if i >= int(start) and i <= int(end):
+ if (i + 1) >= int(start) and (i + 1) <= int(end):
lines.append(line)
_lines[i] = (lineNumbers, line)
- elif i == int(lineNum):
+ elif (i + 1) == int(lineNum):
lines.append(line)
_lines[i] = (lineNumbers, line)
+ else:
+ _lines[i] = (lineNumbers, None)
#source = str(lines)
source = str(_lines)
From 7c0817041c7d8bb4224015f1a42246460d4270d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 02:46:20 +0200
Subject: [PATCH 61/70] Fix debug
---
lib/superfences_ponylang/__init__.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 4adc2c74..9859269f 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -35,12 +35,12 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
start, end = lineNum.split('-')
if (i + 1) >= int(start) and (i + 1) <= int(end):
lines.append(line)
- _lines[i] = (lineNumbers, line)
+ _lines[i] = (lineNum, line)
elif (i + 1) == int(lineNum):
lines.append(line)
- _lines[i] = (lineNumbers, line)
+ _lines[i] = (lineNum, line)
else:
- _lines[i] = (lineNumbers, None)
+ _lines[i] = (lineNum, None)
#source = str(lines)
source = str(_lines)
From fca15401c97b17b24a8c42046aae7a9e7f7f35f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 02:48:40 +0200
Subject: [PATCH 62/70] Better example
---
docs/getting-started/how-it-works.md | 2 +-
lib/superfences_ponylang/__init__.py | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/getting-started/how-it-works.md b/docs/getting-started/how-it-works.md
index 7508759c..ac584f0d 100644
--- a/docs/getting-started/how-it-works.md
+++ b/docs/getting-started/how-it-works.md
@@ -10,7 +10,7 @@ Let's go through that line by line.
## Line 1
-```{ .ponylang snippet="hello-world-main.pony:1-3,6" dedent_subsections=false }
+```{ .ponylang snippet="classes-wombat:1-3,6" dedent_subsections=false }
Lorem ipsum
```
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 9859269f..4adc2c74 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -35,12 +35,12 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
start, end = lineNum.split('-')
if (i + 1) >= int(start) and (i + 1) <= int(end):
lines.append(line)
- _lines[i] = (lineNum, line)
+ _lines[i] = (lineNumbers, line)
elif (i + 1) == int(lineNum):
lines.append(line)
- _lines[i] = (lineNum, line)
+ _lines[i] = (lineNumbers, line)
else:
- _lines[i] = (lineNum, None)
+ _lines[i] = (lineNumbers, None)
#source = str(lines)
source = str(_lines)
From 8aec846af54758f9c09bfcabb0c56154b5cb134c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 02:49:39 +0200
Subject: [PATCH 63/70] improve debug
---
lib/superfences_ponylang/__init__.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 4adc2c74..59ca99e5 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -35,12 +35,12 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
start, end = lineNum.split('-')
if (i + 1) >= int(start) and (i + 1) <= int(end):
lines.append(line)
- _lines[i] = (lineNumbers, line)
+ _lines[i] = (lineNumbers, line, True)
elif (i + 1) == int(lineNum):
lines.append(line)
- _lines[i] = (lineNumbers, line)
+ _lines[i] = (lineNumbers, line, True)
else:
- _lines[i] = (lineNumbers, None)
+ _lines[i] = (lineNumbers, line, False)
#source = str(lines)
source = str(_lines)
From e490856591f988db3d660f2874ab2f1793b49d86 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 02:54:16 +0200
Subject: [PATCH 64/70] Fix snippet path
---
docs/getting-started/how-it-works.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/getting-started/how-it-works.md b/docs/getting-started/how-it-works.md
index ac584f0d..bff50e1d 100644
--- a/docs/getting-started/how-it-works.md
+++ b/docs/getting-started/how-it-works.md
@@ -10,7 +10,7 @@ Let's go through that line by line.
## Line 1
-```{ .ponylang snippet="classes-wombat:1-3,6" dedent_subsections=false }
+```{ .ponylang snippet="classes-wombat.pony:1-3,6" dedent_subsections=false }
Lorem ipsum
```
From 8f35e48f8e76d9726300f1ac3f05fa3caa075683 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 03:00:38 +0200
Subject: [PATCH 65/70] remove debugging output
---
lib/superfences_ponylang/__init__.py | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 59ca99e5..3bda3c1a 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -35,14 +35,14 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
start, end = lineNum.split('-')
if (i + 1) >= int(start) and (i + 1) <= int(end):
lines.append(line)
- _lines[i] = (lineNumbers, line, True)
+ # _lines[i] = (lineNumbers, line, True)
elif (i + 1) == int(lineNum):
lines.append(line)
- _lines[i] = (lineNumbers, line, True)
- else:
- _lines[i] = (lineNumbers, line, False)
+ # _lines[i] = (lineNumbers, line, True)
+ #else:
+ # _lines[i] = (lineNumbers, line, False)
#source = str(lines)
- source = str(_lines)
+ #source = str(_lines)
if 'dedent_subsections' in attrs and attrs.get('dedent_subsections'):
p = re.compile('^\s+')
@@ -58,7 +58,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
for i, line in enumerate(lines):
lines[i] = line[indent:None]
- #source = '\n'.join(lines)
+ source = '\n'.join(lines)
#source = str(base.Config.user_configs.__dict__) + str(TemplateContext) + str(c) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
From b8aa27543adda24f3bcc0ebf23ff0c2fa80e494b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 03:03:00 +0200
Subject: [PATCH 66/70] They already have line breaks
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 3bda3c1a..20a0b35d 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -58,7 +58,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
for i, line in enumerate(lines):
lines[i] = line[indent:None]
- source = '\n'.join(lines)
+ source = ''.join(lines) #'\n'
#source = str(base.Config.user_configs.__dict__) + str(TemplateContext) + str(c) + str(options) + str(attrs) + str(classes) + str(kwargs)
else:
with open(os.getcwd() + "/code-samples/" + snippetPath, 'r') as f:
From 7e9758086d4bc28db5d73039933dbb66b31073a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 03:11:35 +0200
Subject: [PATCH 67/70] Wrap output
---
lib/superfences_ponylang/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 20a0b35d..28dd3958 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -73,7 +73,7 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
except:
raise SuperFencesException('Could not highlight source code "%s" passed' % (source))
- return highlighted
+ return '%s' % highlighted
return """
From 89cf63db7c4010e8f00dd174ade1dc0b2425056b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 03:16:47 +0200
Subject: [PATCH 68/70] Navigation
---
lib/superfences_ponylang/__init__.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 28dd3958..97d9b293 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -73,7 +73,14 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
except:
raise SuperFencesException('Could not highlight source code "%s" passed' % (source))
- return '%s' % highlighted
+ return """
+
+
+
+
+
+ %s
+ """ % highlighted
return """
From f738e3140e8cdd4f989b04c8de6222c728315252 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 03:21:14 +0200
Subject: [PATCH 69/70] Wrap in pre
---
lib/superfences_ponylang/__init__.py | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index 97d9b293..bc952055 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -74,12 +74,14 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
raise SuperFencesException('Could not highlight source code "%s" passed' % (source))
return """
-
-
-
-
-
- %s
+
+
+
+
+
+
+ %s
+
""" % highlighted
return """
From aba775672a0ec9741808d707562438906b641980 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20H=C3=A4drich?=
<11225821+shaedrich@users.noreply.github.com>
Date: Thu, 6 Jun 2024 04:00:56 +0200
Subject: [PATCH 70/70] Only render run button when runnable
---
docs/getting-started/hello-world.md | 2 +-
docs/getting-started/how-it-works.md | 2 +-
lib/superfences_ponylang/__init__.py | 6 +++---
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/docs/getting-started/hello-world.md b/docs/getting-started/hello-world.md
index 526e01bc..68144103 100644
--- a/docs/getting-started/hello-world.md
+++ b/docs/getting-started/hello-world.md
@@ -17,7 +17,7 @@ __Does the name of the file matter?__ Not to the compiler, no. Pony doesn't care
In your file, put the following code:
-```{ .ponylang snippet="hello-world-main.pony" dedent_subsections=false }
+```{ .ponylang snippet="hello-world-main.pony" dedent_subsections=false runnable=false }
Gibberish
```
diff --git a/docs/getting-started/how-it-works.md b/docs/getting-started/how-it-works.md
index bff50e1d..65bc6d83 100644
--- a/docs/getting-started/how-it-works.md
+++ b/docs/getting-started/how-it-works.md
@@ -10,7 +10,7 @@ Let's go through that line by line.
## Line 1
-```{ .ponylang snippet="classes-wombat.pony:1-3,6" dedent_subsections=false }
+```{ .ponylang snippet="classes-wombat.pony:1-3,6" dedent_subsections=false runnable=true }
Lorem ipsum
```
diff --git a/lib/superfences_ponylang/__init__.py b/lib/superfences_ponylang/__init__.py
index bc952055..8e7e9d66 100644
--- a/lib/superfences_ponylang/__init__.py
+++ b/lib/superfences_ponylang/__init__.py
@@ -73,12 +73,12 @@ def format(source, language, css_class, options, md, classes=None, id_value='',
except:
raise SuperFencesException('Could not highlight source code "%s" passed' % (source))
- return """
+ return f"""
-
-
+ {'' if attrs.get('runnable', false) else ''}
+ {'' if attrs.get('runnable', false) else ''}
%s