Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pandoc markdown and notes #637

Closed
framatophe opened this issue Jul 15, 2019 · 4 comments
Closed

Pandoc markdown and notes #637

framatophe opened this issue Jul 15, 2019 · 4 comments
Labels
A: Backend Code running on the server C: Enhancement New feature or request Good first issue Good for newcomers
Milestone

Comments

@framatophe
Copy link

The markdown syntax used in Plume is quite satisfactory, but there should be at least one small correction: adapt the syntax of the notes to the pandoc flavor.

Usually, when writing markdown, most editors use the following syntax to create note calls and references:

Lorem ipsum[^note] partibus quidem

[^note]: This is a note.

However, with Plume, you have to use:

Lorem ipsum[^note] partibus quidem

[^note] This is a note.

The absence of the colon prevents you from writing in markdown in a classic editor, then importing the text into Plume without adjusting the notes. The opposite is also true.

@elegaanz elegaanz added A: Backend Code running on the server C: Enhancement New feature or request Good first issue Good for newcomers P: Low labels Jul 18, 2019
@elegaanz elegaanz added this to the 1.0 milestone Jul 18, 2019
@papey
Copy link
Contributor

papey commented Aug 1, 2019

Working on it. Adding some pointers if anyone else is interested. All the render is made in the md_to_html function.

Here is an idea proposed by @AnaGelez :

the best solution would be to look for pandoc-style notes in md at the beginning of the function (iterating over its lines, and keeping those that are in the good format) and just remove the first :

@elegaanz elegaanz removed the P: Low label Aug 1, 2019
@papey
Copy link
Contributor

papey commented Nov 17, 2019

Since cpull-markdown is used in Plume to translate md to html, I looked at https://github.com/raphlinus/pulldown-cmark/blob/master/tests/suite/footnotes.rs and things looks good on this side. There is no closed issue about a bug like this, in the upstream package, any ideas ?

@papey
Copy link
Contributor

papey commented Nov 19, 2019

Ok, here is an update of what i've found so far :

md_to_html function output LGTM, here is a test example :

Code :

    #[test]
    fn test_markdown_notes() {
        let md = r##"Awesome[^1]

[^1]: here is the note definition !
"##;

        let (s, _, _) = md_to_html(md, None, false, None);

        println!("{}", s)

    }

Output :

<p>Awesome<sup class="footnote-reference"><a href="#1">1</a></sup></p>
<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>
<p>here is the note definition</p>
</div>

Here is the result I get on the final page generated by Plume :

With [^n]:

<article class="e-content" dir="auto">
<p>Awesome<sup><a href="#postcontent-1" rel="noopener noreferrer">1</a></sup></p>
<p><br></p>
<div id="postcontent-1"><sup>1</sup>
<p>here is the note definition !</p>
</div>
</article>

With [^n] 

<article class="e-content" dir="auto">
<p>Awesome<sup><a href="#postcontent-1" rel="noopener noreferrer">1</a></sup></p>
<p><br></p>
<p><sup><a href="#postcontent-1" rel="noopener noreferrer">1</a></sup> here is the note definition !</p>
</article>

Now, i'm having hard times finding where the page get translated from md_to_html output to final page. Looks like this where he can find the root cause of this bug. If you have some ideas, let me know.

@papey
Copy link
Contributor

papey commented Nov 19, 2019

Still digging on this, here is a test of SafeString related functions.

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_html_note_to_safe_string() {
        let html = r##"<p>Awesome<sup class="footnote-reference"><a href="#1">1</a></sup>
<sup class="footnote-reference"><a href="#1">1</a></sup>: here is the note definition !</p>"##;

        let s = SafeString::new(html);

        println!("{}", s);
    }
}

Output :

<p>Awesome<sup><a href="#postcontent-1" rel="noopener noreferrer">1</a></sup>
<sup><a href="#postcontent-1" rel="noopener noreferrer">1</a></sup>: here is the note definition !</p>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: Backend Code running on the server C: Enhancement New feature or request Good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants