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/comment/__init__.py b/obsidian_support/conversion/comment/__init__.py new file mode 100644 index 0000000..e69de29 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/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/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/test_conversions.py b/test/test_conversions.py index c058993..f3c05b5 100644 --- a/test/test_conversions.py +++ b/test/test_conversions.py @@ -6,6 +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.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 @@ -41,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'))