kotajacob / goldmark-gemtext

Read-only mirror of https://git.sr.ht/~kota/goldmark-gemtext

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

goldmark-gemtext godocs.io builds.sr.ht status

A gemtext renderer for goldmark. You can use this library to parse commonmark markdown (with support for autolinks and strikethrough) and convert it into nice clean looking gemtext (with some options). This library does the heavy lifting for gemgen.

Several markdown extensions are supported and can be enabled as goldmark parser extensions. The following are currently supported: extension.Linkify, extension.Strikethrough, and wiki.Wiki.

You create a renderer with New(option...) and pass in options:

var src = `
# This is a heading

This is a [paragraph](https://en.wikipedia.org/wiki/Paragraph) with [some
links](https://en.wikipedia.org/wiki/Hyperlink) in it.

Next we'll have a list of some musicians I like, but as an individual list of
links. One of the neat features of goldmark-gemtext is that it recognizes when
a "paragraph" is really just a list of links and handles it as if it's a list
of links by simply converting them to the gemtext format. I wasn't able to find
any other markdown to gemtext tools that could do this so it was the
inspiration for writing this in the first place.

[Noname](https://nonameraps.bandcamp.com/)\
[Milo](https://afrolab9000.bandcamp.com/album/so-the-flies-dont-come)\
[Busdriver](https://busdriver-thumbs.bandcamp.com/)\
[Neat Beats](https://www.youtube.com/watch?v=X6kGg31G0As)\
[Ratatat](http://www.ratatatmusic.com/)\
[Sylvan Esso](https://www.sylvanesso.com/)\
[Phoebe Bridgers](https://phoebefuckingbridgers.com/)
`

// create markdown parser
var buf bytes.Buffer
md := goldmark.New(
  goldmark.WithExtensions(
    extension.Linkify,
    extension.Strikethrough,
  ),
)

// set some options
var options = []Option{WithHeadingLink(HeadingLinkAuto), WithCodeSpan(CodeSpanMarkdown)}

md.SetRenderer(New(options...))
_ = md.Convert([]byte(src), &buf) // ignoring errors for example
fmt.Println(buf.String())

There's a bunch of options. You can read them in the documentaton. If you have suggestions, issues, or anything else drop an email in the mailing list.

About

Read-only mirror of https://git.sr.ht/~kota/goldmark-gemtext

License:GNU General Public License v3.0


Languages

Language:Go 100.0%