Skip to content

Commit

Permalink
Ignore frontmatter in Markdown sources
Browse files Browse the repository at this point in the history
  • Loading branch information
hunyadi committed Mar 2, 2024
1 parent 91c3619 commit f47d568
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 10 additions & 4 deletions md2conf/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,19 +538,25 @@ def __init__(
path = os.path.abspath(path)

with open(path, "r") as f:
html = markdown_to_html(f.read())
text = f.read()

# extract Confluence page ID
qualified_id, html = extract_qualified_id(html)
qualified_id, text = extract_qualified_id(text)
if qualified_id is None:
raise ValueError("missing Confluence page ID")
self.id = qualified_id

# extract 'generated-by' tag text
generated_by_tag, html = extract_value(
r"<!--\s+generated-by:\s*(.*)\s+-->", html
generated_by_tag, text = extract_value(
r"<!--\s+generated-by:\s*(.*)\s+-->", text
)

# extract frontmatter
frontmatter, text = extract_value(r"(?ms)\A---$(.+?)^---$", text)

# convert to HTML
html = markdown_to_html(text)

# parse Markdown document
if self.options.generated_by is not None:
generated_by = self.options.generated_by
Expand Down
8 changes: 8 additions & 0 deletions sample/sibling.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
---
title: "Markdown example document"
tags: ["Markdown", "Confluence", "md", "wiki"]
description: >
this is
a multiline string
---

<!-- confluence-page-id: 86090481730 -->

If you are a user who wants to publish pages to Confluence, you should install the package [markdown-to-confluence](https://pypi.org/project/markdown-to-confluence/) from PyPI. If you are a developer who wants to contribute, you should clone the repository [md2conf](https://github.com/hunyadi/md2conf) from GitHub.
Expand Down

0 comments on commit f47d568

Please sign in to comment.