kovetskiy / mark

Sync your markdown files with Confluence pages.
https://samizdat.dev
Other
972 stars 143 forks source link

Wrong title when using --title-from-h1 and inline template macros #414

Open cabidop opened 5 months ago

cabidop commented 5 months ago

What happened?

When trying to use inline template macros with the --title-from-h1 parameter, instead of using the leading H1 header for the Confluence page title mark is using the template name of the first macro minus its first character (i.e. if the first inline template is defined as Template: #my_template the Confluence title becomes y_template).

What did you expect to happen?

The Confluence title matches the actual leading H1 header.

How can we reproduce the behavior you experienced?

  1. Enable the --title-from-h1 parameter.
  2. Create a document with no <!-- Title --> header and at least one <!-- Macro --> header with an inline template defined.
  3. Try to sync the document with Confluence.

Minimal markdown example where the Confluence title becomes nline instead of Some title:

<!-- Space: Test -->
<!-- Parent: Test -->
<!-- Macro: <test />
        Template: #inline
        inline: Some test
    -->

# Some title

<test />

Information (please complete the following information)

Logs or other output

No relevant logs that might highlight or help debugging the issue.

Additional context

Looks like the regex used in the ExtractDocumentLeadingH1 function might be the culprit, as it does match the observed behaviour.

mrueg commented 5 months ago

Good point, the extraction logic should probably be part of the custom parser and not be done via a regular expression.

cabidop commented 5 months ago

Hey @mrueg, not fully sure of what the solution you proposed implies (moving the extraction to the custom parser) but a quick fix could be to just update the regex to better fit the Markdown specification for headings. Something like this should do the job (I can open a PR to add the change together with some tests): ^\s{0,3}#\s+(.*)(\s+#+)?\s*\n