diff --git a/README.md b/README.md index 6e2e7f9..56b5e97 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ plugins: ## features - `obsidian callout/block styled admonition` -> `mkdocs-material admonition` +- `obsidian comment` -> `html comment` - `obsidian wikilink image` -> `mkdocs-material mdlink image` & `image with md_in_html` - `obsidian tags` -> `mkdocs-material search` @@ -41,3 +42,6 @@ plugins: - https://github.com/sondregronas/mkdocs-callouts - https://github.com/orbikm/mkdocs-ezlinks-plugin + + +This is an %%inline%% comment. diff --git a/docs/features/admonition/backquotes.md b/docs/features/admonition/backquotes.md index 98b1511..405aa80 100644 --- a/docs/features/admonition/backquotes.md +++ b/docs/features/admonition/backquotes.md @@ -14,27 +14,32 @@ title: Admonition Backquotes === "obsidian markdown" - ```ad-tip - title: This is a tip - This is the content of the admonition tip. - ``` +```` +```ad-tip +title: This is a tip + +This is the content of the admonition tip. +``` +```` === "obsidian rendered" - ![[images/backquotes_1.png]] +![[images/backquotes_1.png]] ### mkdocs-material admonition === "mkdocs-material markdown" - ``` - !!!tip "This is a tip" - - This is the content of the admonition tip. - ``` +``` +!!!tip "This is a tip" + + This is the content of the admonition tip. +``` === "mkdocs-material rendered" - !!!tip "This is a tip" - - This is the content of the admonition tip. +```ad-tip +title: This is a tip + +This is the content of the admonition tip. +``` \ No newline at end of file diff --git a/docs/features/admonition/callout.md b/docs/features/admonition/callout.md index 38d2fd3..3b8694f 100644 --- a/docs/features/admonition/callout.md +++ b/docs/features/admonition/callout.md @@ -2,7 +2,7 @@ title: Admonition Callout --- > [!note] feature - admonition callout -> convert `obsidian callout` to `mkdocs-material admonition` +> Convert `obsidian callout` to `mkdocs-material admonition` > > - [obsidian callout](https://help.obsidian.md/Editing+and+formatting/Callouts) > - [mkdocs-material admonition](https://squidfunk.github.io/mkdocs-material/reference/admonitions/) @@ -14,36 +14,35 @@ See [Demo](demo) for more examples === "obsidian markdown" - ``` - > [!note] haha - > I am obsidian callout! - > - > I became mkdocs admonition! - ``` +``` +> [!note] haha +> I am obsidian callout! +> +> I became mkdocs admonition! +``` === "obsidian rendered" - ![[images/callout_1.png]] +![[images/callout_1.png]] ### mkdocs-material admonition === "mkdocs-material markdown" - ``` - !!!note "haha" - - I am obsidian callout! - I became mkdocs admonition! - ``` +``` +!!!note "haha" + + I am obsidian callout! + I became mkdocs admonition! +``` === "mkdocs-material rendered" - !!!note "haha" - - I am obsidian callout! - - I became mkdocs admonition! +> [!note] haha +> I am obsidian callout! +> +> I became mkdocs admonition! @@ -53,30 +52,28 @@ See [Demo](demo) for more examples === "obsidian markdown" - ``` - > [!faq]- Are callouts foldable? - > Yes! In a foldable callout, the contents are hidden when the callout is collapsed. - ``` +``` +> [!faq]- Are callouts foldable? +> Yes! In a foldable callout, the contents are hidden when the callout is collapsed. +``` === "obsidian rendered" - ![[images/callout_2.png]] +![[images/callout_2.png]] ### mkdocs-material admonition === "mkdocs-material markdown" - ``` - ??? note "Are callouts foldable?" - - Yes! In a foldable callout, the contents are hidden when the callout is collapsed. - ``` +``` +??? faq "Are callouts foldable?" + Yes! In a foldable callout, the contents are hidden when the callout is collapsed. +``` === "mkdocs-material rendered" - ??? note "Are callouts foldable?" - - Yes! In a foldable callout, the contents are hidden when the callout is collapsed. +> [!faq]- Are callouts foldable? +> Yes! In a foldable callout, the contents are hidden when the callout is collapsed. ## 💡 Notes diff --git a/docs/features/comment/images/comment_1.png b/docs/features/comment/images/comment_1.png new file mode 100644 index 0000000..97e6588 Binary files /dev/null and b/docs/features/comment/images/comment_1.png differ diff --git a/docs/features/comment/index.md b/docs/features/comment/index.md new file mode 100644 index 0000000..a49dd03 --- /dev/null +++ b/docs/features/comment/index.md @@ -0,0 +1,33 @@ +--- +title: Comment +--- + +> [!note] feature - comment +> Convert `obsidian comments` to `HTML Comment Tag` +> +> - [obsidian comments](https://help.obsidian.md/Editing+and+formatting/Basic+formatting+syntax#Comments) +> - [HTML Comment Tag](https://www.w3schools.com/tags/tag_comment.asp) + +## Inline Comment + +=== "obsidian markdown" + + ``` + This is an %%inline%% comment. + ``` + +=== "obsidian reading view" + + ![[images/comment_1.png]] + +### mkdocs-material admonition + +=== "mkdocs-material markdown" + + ``` + This is an comment. + ``` + +=== "mkdocs-material rendered" + + This is an %%inline%% comment. \ No newline at end of file diff --git a/docs/features/image-link/index.md b/docs/features/image-link/index.md index e7de989..3a30a6c 100644 --- a/docs/features/image-link/index.md +++ b/docs/features/image-link/index.md @@ -3,7 +3,7 @@ title: Image-Link --- > [!note] feature - image-link -> convert `obsidian wikilink for images` to `mkdocs-material md-link for images` +> Convert `obsidian wikilink for images` to `mkdocs-material md-link for images` obsidian support [`wikilink`](https://help.obsidian.md/Linking+notes+and+files/Internal+links) with [embbe an image in a note](https://help.obsidian.md/Linking+notes+and+files/Embedding+files#Embed+an+image+in+a+note) diff --git a/docs/features/tags/index.md b/docs/features/tags/index.md index 53764dc..e253123 100644 --- a/docs/features/tags/index.md +++ b/docs/features/tags/index.md @@ -2,7 +2,7 @@ title: Tags --- > [!note] feature - tags -> convert `obsidian tags` to `mkdocs-material search` +> Convert `obsidian tags` to `mkdocs-material search` > > - [obsidian tags](https://help.obsidian.md/Editing+and+formatting/Tags) > - [mkdocs-material search](https://squidfunk.github.io/mkdocs-material/setup/setting-up-site-search/) @@ -17,7 +17,7 @@ title: Tags === "mkdocs-material rendered" - This is just an **obsidian**{: .hash} tag. Click to go to the search bar + This is just an #obsidian tag. Click to go to the search bar ## How to activate diff --git a/obsidian_support/conversion/excalidraw/__init__.py b/obsidian_support/conversion/comment/__init__.py similarity index 100% rename from obsidian_support/conversion/excalidraw/__init__.py rename to obsidian_support/conversion/comment/__init__.py diff --git a/obsidian_support/conversion/comment/comment.py b/obsidian_support/conversion/comment/comment.py new file mode 100644 index 0000000..f9995ed --- /dev/null +++ b/obsidian_support/conversion/comment/comment.py @@ -0,0 +1,31 @@ +import re + +from mkdocs.structure.pages import Page +from overrides import override + +from obsidian_support.conversion.abstract_conversion import AbstractConversion, SyntaxGroup + +""" +A strategy that convert [obsidian comments](https://help.obsidian.md/Editing+and+formatting/Basic+formatting+syntax#Comments) +to [HTML Comment Tag](https://www.w3schools.com/tags/tag_comment.asp) + +Examples: +given : `This is an %%inline%% comment.` +converted : `This is an comment.` +""" + + +class CommentConversion(AbstractConversion): + + @property + @override + def obsidian_regex_pattern(self): + # OBSIDIAN_COMMENT_REGEX + return re.compile(r"%%(?P[\S\s]*?)%%") + + @override + def convert(self, syntax_groups: SyntaxGroup, page: Page) -> str: + return self._convert_comment(*syntax_groups) + + def _convert_comment(self, comment): + return f"" diff --git a/obsidian_support/conversion/excalidraw/excalidraw.py b/obsidian_support/conversion/excalidraw/excalidraw.py deleted file mode 100644 index e6e7fe5..0000000 --- a/obsidian_support/conversion/excalidraw/excalidraw.py +++ /dev/null @@ -1,38 +0,0 @@ -import re - -from mkdocs.structure.pages import Page -from overrides import override - -from obsidian_support.conversion.abstract_conversion import AbstractConversion, SyntaxGroup - -""" -a strategy that convert [excalidraw link] to [excalidraw kroki code block] -""" - - -class ExcalidrawConversion(AbstractConversion): - excalidraw_json_pattern = re.compile(r"```json\n(?P[\\s\\S]+)\n```") - - @property - @override - def obsidian_regex_pattern(self): - # OBSIDIAN_EXCALIDRAW_PATH_REGEX - return re.compile(r"!\[\[(?P[^|^\]]+.excalidraw)]]") - - @override - def convert(self, syntax_groups: SyntaxGroup, page: Page) -> str: - return self._convert_excalidraw(*syntax_groups, page) - - def _convert_excalidraw(self, excalidraw_path: str, page: Page) -> str: - src_uri = page.file.src_uri - src_dir_index = src_uri[:len(src_uri) - 1].rfind('/') - src_dir_path = src_uri[:src_dir_index] + "/" - excalidraw_file_path = "docs/" + src_dir_path + excalidraw_path + '.md' - - f = open(excalidraw_file_path, 'r') - excalidraw_markdown = f.read() - excalidraw_json_match = self.excalidraw_json_pattern.search(excalidraw_markdown) - excalidraw_json = excalidraw_json_match.group('json') - f.close() - - return f"```kroki-excalidraw\n{excalidraw_json}\n```" diff --git a/obsidian_support/plugin.py b/obsidian_support/plugin.py index 9f58e03..29048f5 100644 --- a/obsidian_support/plugin.py +++ b/obsidian_support/plugin.py @@ -2,6 +2,7 @@ from obsidian_support.conversion.admonition.admonition_backquotes import AdmonitionBackquotesConversion from obsidian_support.conversion.admonition.admonition_callout import AdmonitionCalloutConversion +from obsidian_support.conversion.comment.comment import CommentConversion from obsidian_support.conversion.image_link.image_internal_link import ImageInternalLinkConversion from obsidian_support.conversion.image_link.image_web_link import ImageWebLinkConversion from obsidian_support.conversion.tags.tags import TagsConversion @@ -22,6 +23,7 @@ def __init__(self): self.image_web_link_conversions = ImageWebLinkConversion() self.image_internal_link_conversion = ImageInternalLinkConversion() self.tags_conversion = TagsConversion() + self.comment_conversion = CommentConversion() def on_page_markdown(self, markdown, page, config, files): # apply conversions @@ -30,4 +32,5 @@ def on_page_markdown(self, markdown, page, config, files): markdown = markdown_convert(markdown, page, self.image_web_link_conversions) markdown = markdown_convert(markdown, page, self.image_internal_link_conversion) markdown = markdown_convert(markdown, page, self.tags_conversion) + markdown = markdown_convert(markdown, page, self.comment_conversion) return markdown diff --git a/setup.py b/setup.py index a9824fd..59a1ae3 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages -VERSION_NUMBER = '1.0.0' +VERSION_NUMBER = '1.1.0' def read_file(fname): diff --git a/test/markdowns/comment/expected/basic.md b/test/markdowns/comment/expected/basic.md new file mode 100644 index 0000000..b10de53 --- /dev/null +++ b/test/markdowns/comment/expected/basic.md @@ -0,0 +1,9 @@ +# Comment + +This is an comment. + + \ No newline at end of file diff --git a/test/markdowns/comment/given/basic.md b/test/markdowns/comment/given/basic.md new file mode 100644 index 0000000..70733e7 --- /dev/null +++ b/test/markdowns/comment/given/basic.md @@ -0,0 +1,9 @@ +# Comment + +This is an %%inline%% comment. + +%% +This is a block comment. + +Block comments can span multiple lines. +%% \ No newline at end of file diff --git a/test/markdowns/excalidraw/expected/basic.md b/test/markdowns/excalidraw/expected/basic.md deleted file mode 100644 index 8aa9d7f..0000000 --- a/test/markdowns/excalidraw/expected/basic.md +++ /dev/null @@ -1,103 +0,0 @@ -Haha - -```kroki-excalidraw -{ - "type": "excalidraw", - "version": 2, - "source": "https://excalidraw.com", - "elements": [ - { - "id": "fGgjhTPz5dO0705rh7Wl5", - "type": "diamond", - "x": -129.57061767578125, - "y": -233.2157211303711, - "width": 308.1851806640625, - "height": 322.06085205078125, - "angle": 0, - "strokeColor": "#000000", - "backgroundColor": "transparent", - "fillStyle": "hachure", - "strokeWidth": 1, - "strokeStyle": "solid", - "roughness": 1, - "opacity": 100, - "groupIds": [], - "roundness": { - "type": 2 - }, - "seed": 200885532, - "version": 29, - "versionNonce": 2132409252, - "isDeleted": false, - "boundElements": null, - "updated": 1677485414044, - "link": null, - "locked": false - }, - { - "id": "bsRIFFA3", - "type": "text", - "x": 0.77545166015625, - "y": -93.32927703857422, - "width": 51, - "height": 25, - "angle": 0, - "strokeColor": "#000000", - "backgroundColor": "transparent", - "fillStyle": "hachure", - "strokeWidth": 1, - "strokeStyle": "solid", - "roughness": 1, - "opacity": 100, - "groupIds": [], - "roundness": null, - "seed": 421717796, - "version": 17, - "versionNonce": 825917092, - "isDeleted": false, - "boundElements": null, - "updated": 1677485416842, - "link": null, - "locked": false, - "text": "Test", - "rawText": "Test", - "fontSize": 20, - "fontFamily": 1, - "textAlign": "left", - "verticalAlign": "top", - "baseline": 18, - "containerId": null, - "originalText": "Test" - } - ], - "appState": { - "theme": "light", - "viewBackgroundColor": "#ffffff", - "currentItemStrokeColor": "#000000", - "currentItemBackgroundColor": "transparent", - "currentItemFillStyle": "hachure", - "currentItemStrokeWidth": 1, - "currentItemStrokeStyle": "solid", - "currentItemRoughness": 1, - "currentItemOpacity": 100, - "currentItemFontFamily": 1, - "currentItemFontSize": 20, - "currentItemTextAlign": "left", - "currentItemStartArrowhead": null, - "currentItemEndArrowhead": "arrow", - "scrollX": 484.34649658203125, - "scrollY": 337.14605712890625, - "zoom": { - "value": 1 - }, - "currentItemRoundness": "round", - "gridSize": null, - "colorPalette": {}, - "currentStrokeOptions": null, - "previousGridSize": null - }, - "files": {} -} -``` - -Last Line \ No newline at end of file diff --git a/test/markdowns/excalidraw/given/basic.md b/test/markdowns/excalidraw/given/basic.md deleted file mode 100644 index f9b1f49..0000000 --- a/test/markdowns/excalidraw/given/basic.md +++ /dev/null @@ -1,5 +0,0 @@ -Haha - -![[test.excalidraw]] - -Last Line \ No newline at end of file diff --git a/test/markdowns/excalidraw/given/test.excalidraw.md b/test/markdowns/excalidraw/given/test.excalidraw.md deleted file mode 100644 index 3380aed..0000000 --- a/test/markdowns/excalidraw/given/test.excalidraw.md +++ /dev/null @@ -1,114 +0,0 @@ ---- - -excalidraw-plugin: parsed -tags: [excalidraw] - ---- -==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠== - - -# Text Elements -Test ^bsRIFFA3 - -%% -# Drawing -```json -{ - "type": "excalidraw", - "version": 2, - "source": "https://excalidraw.com", - "elements": [ - { - "id": "fGgjhTPz5dO0705rh7Wl5", - "type": "diamond", - "x": -129.57061767578125, - "y": -233.2157211303711, - "width": 308.1851806640625, - "height": 322.06085205078125, - "angle": 0, - "strokeColor": "#000000", - "backgroundColor": "transparent", - "fillStyle": "hachure", - "strokeWidth": 1, - "strokeStyle": "solid", - "roughness": 1, - "opacity": 100, - "groupIds": [], - "roundness": { - "type": 2 - }, - "seed": 200885532, - "version": 29, - "versionNonce": 2132409252, - "isDeleted": false, - "boundElements": null, - "updated": 1677485414044, - "link": null, - "locked": false - }, - { - "id": "bsRIFFA3", - "type": "text", - "x": 0.77545166015625, - "y": -93.32927703857422, - "width": 51, - "height": 25, - "angle": 0, - "strokeColor": "#000000", - "backgroundColor": "transparent", - "fillStyle": "hachure", - "strokeWidth": 1, - "strokeStyle": "solid", - "roughness": 1, - "opacity": 100, - "groupIds": [], - "roundness": null, - "seed": 421717796, - "version": 17, - "versionNonce": 825917092, - "isDeleted": false, - "boundElements": null, - "updated": 1677485416842, - "link": null, - "locked": false, - "text": "Test", - "rawText": "Test", - "fontSize": 20, - "fontFamily": 1, - "textAlign": "left", - "verticalAlign": "top", - "baseline": 18, - "containerId": null, - "originalText": "Test" - } - ], - "appState": { - "theme": "light", - "viewBackgroundColor": "#ffffff", - "currentItemStrokeColor": "#000000", - "currentItemBackgroundColor": "transparent", - "currentItemFillStyle": "hachure", - "currentItemStrokeWidth": 1, - "currentItemStrokeStyle": "solid", - "currentItemRoughness": 1, - "currentItemOpacity": 100, - "currentItemFontFamily": 1, - "currentItemFontSize": 20, - "currentItemTextAlign": "left", - "currentItemStartArrowhead": null, - "currentItemEndArrowhead": "arrow", - "scrollX": 484.34649658203125, - "scrollY": 337.14605712890625, - "zoom": { - "value": 1 - }, - "currentItemRoundness": "round", - "gridSize": null, - "colorPalette": {}, - "currentStrokeOptions": null, - "previousGridSize": null - }, - "files": {} -} -``` -%% \ No newline at end of file diff --git a/test/test_conversions.py b/test/test_conversions.py index 15e017e..f3c05b5 100644 --- a/test/test_conversions.py +++ b/test/test_conversions.py @@ -6,7 +6,7 @@ from obsidian_support.conversion.abstract_conversion import AbstractConversion from obsidian_support.conversion.admonition.admonition_backquotes import AdmonitionBackquotesConversion from obsidian_support.conversion.admonition.admonition_callout import AdmonitionCalloutConversion -from obsidian_support.conversion.excalidraw.excalidraw import ExcalidrawConversion +from obsidian_support.conversion.comment.comment import CommentConversion from obsidian_support.conversion.image_link.image_internal_link import ImageInternalLinkConversion from obsidian_support.conversion.image_link.image_web_link import ImageWebLinkConversion from obsidian_support.conversion.tags.tags import TagsConversion @@ -27,12 +27,6 @@ def test_admonition_backquotes_conversion(test): assert_template("admonition/admonition_backquotes", test, AdmonitionBackquotesConversion()) -@pytest.mark.skip -@pytest.mark.parametrize("test", ['basic']) -def test_excalidraw_conversion(test): - assert_template("excalidraw", test, ExcalidrawConversion()) - - @pytest.mark.parametrize("test", ['basic', 'size', 'caption', 'size_caption']) def test_image_internal_link_conversion(test): assert_template("image_link/image_internal_link", test, ImageInternalLinkConversion()) @@ -48,6 +42,11 @@ def test_tag_conversion(test): assert_template("tags", test, TagsConversion()) +@pytest.mark.parametrize("test", ['basic']) +def test_comment_conversion(test): + assert_template("comment", test, CommentConversion()) + + def assert_template(conversion_name: str, test: str, conversion: AbstractConversion): with ExitStack() as stack: src = stack.enter_context(open(f"markdowns/{conversion_name}/given/{test}.md", 'r'))