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

Markup -> Plaintext #18

Closed
tlienart opened this issue Mar 13, 2021 · 2 comments
Closed

Markup -> Plaintext #18

tlienart opened this issue Mar 13, 2021 · 2 comments

Comments

@tlienart
Copy link
Contributor

Hello Mike,

In the context of dealing with RSS (not the most fun thing to figure out), it'd be useful to have a way to go from "markdown" to "plaintext". The reason is that in RSS the <description> field, if given along with a <content:encoded> one, should be plain text (no markup). You can write <[CDATA... stuff but in theory you shouldn't, the encoding should go in the content encoded.

As a result the useful thing to have is a way for people to write:

+++
abstract = "This is a description of the blog post with **markup** and [links](https://juliacon.org)"
+++

{{insert abstract}}

... Rest of the blog post ...

and have the {{insert abstract}} do two things:

  • insert the markup-ed text in the blog post as standard, where it would eventually be converted to HTML (standard path MD -> X)
  • add an RSS item entry where the <description> gets plaintext(abstract), in the above case:
This is a description of the blog post with markup and links.

so that would use a "reverse" path: MD -> text. Is that doable easily with common mark?

Thanks!

@MichaelHatherly
Copy link
Owner

Hey,

Kind of depends on how feature complete you'd want the plaintext to be I guess. Something like the following already does an alright job of downgrading to plaintext:

julia> using CommonMark

julia> ast = cm"This is a description of the blog post with **markup** and [links](https://juliacon.org)";

julia> function plaintext(io, ast)
           for (node, enter) in ast
               isa(node.t, CommonMark.Text) && print(io, node.literal)
           end
       end
plaintext (generic function with 1 method)

julia> plaintext(stdout, ast)
This is a description of the blog post with markup and links

@tlienart
Copy link
Contributor Author

Thanks for the quick response! I think this does the job just fine :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants