Skip to content

Commit

Permalink
Merge pull request #25 from ndy2/23-comment-convert
Browse files Browse the repository at this point in the history
23 comment convert
  • Loading branch information
ndy2 authored Feb 22, 2024
2 parents 9c8c517 + 76bb042 commit 4e0ef30
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 315 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -41,3 +42,6 @@ plugins:

- https://github.com/sondregronas/mkdocs-callouts
- https://github.com/orbikm/mkdocs-ezlinks-plugin


This is an %%inline%% comment.
31 changes: 18 additions & 13 deletions docs/features/admonition/backquotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
61 changes: 29 additions & 32 deletions docs/features/admonition/callout.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand All @@ -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!


Expand All @@ -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
Expand Down
Binary file added docs/features/comment/images/comment_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions docs/features/comment/index.md
Original file line number Diff line number Diff line change
@@ -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 <!--inline--> comment.
```

=== "mkdocs-material rendered"

This is an %%inline%% comment.
2 changes: 1 addition & 1 deletion docs/features/image-link/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions docs/features/tags/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand All @@ -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

Expand Down
31 changes: 31 additions & 0 deletions obsidian_support/conversion/comment/comment.py
Original file line number Diff line number Diff line change
@@ -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 <!--inline--> comment.`
"""


class CommentConversion(AbstractConversion):

@property
@override
def obsidian_regex_pattern(self):
# OBSIDIAN_COMMENT_REGEX
return re.compile(r"%%(?P<comment>[\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"<!--{comment}-->"
38 changes: 0 additions & 38 deletions obsidian_support/conversion/excalidraw/excalidraw.py

This file was deleted.

3 changes: 3 additions & 0 deletions obsidian_support/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
9 changes: 9 additions & 0 deletions test/markdowns/comment/expected/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Comment

This is an <!--inline--> comment.

<!--
This is a block comment.
Block comments can span multiple lines.
-->
9 changes: 9 additions & 0 deletions test/markdowns/comment/given/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Comment

This is an %%inline%% comment.

%%
This is a block comment.

Block comments can span multiple lines.
%%
Loading

0 comments on commit 4e0ef30

Please sign in to comment.