Commit graph

31 commits

Author SHA1 Message Date
Timur Demin
8135d1e0b3
Update heading renderer to latest Gemini spec
Gemini spec p. 5.5.1 used to only allow up to three #-s in a heading
before requiring a mandatory space. It changed to an optional space in
recent updates, allowing to no longer pad Markdown H4-H6.

As clients treat everything after ### a title continuation, the renderer
will now insert H4-H6 verbatim; the end-user behavior doesn't change as
extra space means nothing for a Gemtext renderer displaying the title in
a special way.

Relates to #1.

PS: Gemini spec doesn't appear to be properly versioned, saying the
latest version is 0.14.3, 2020-11-29. The discussion on #1 clearly shows
it used to be different a while ago.
2021-09-17 23:02:46 +05:00
Timur Demin
45180f9315
Remove an outdated TODO 2021-09-17 22:55:44 +05:00
Timur Demin
7e19930b1b
Add missing copyright headers 2021-09-17 22:37:10 +05:00
Timur Demin
9778ada128
Parse metadata in all Hugo formats
This makes gmnhg parse TOML/YAML/JSON/org-mode front matter in Hugo posts.

This also makes the library no longer render metadata in posts, removing
the API to do so. The metadata parsing code itself moves to
internal/gmnhg.

As the library no longer has a preset to include metadata in rendered
document, md2gmn will from now on silently discard front matter if it
encounters any.

Fixes #28. Unblocks #13.
2021-09-17 22:34:03 +05:00
Timur Demin
bcc3d8b730
Implement a generic links & text extractor
Before this, links would only be scraped from paragraphs and
rendered as a block after parent paragraph. This replaces this logic
with a generic links extractor that would recursively collect every link
from any parent node, including footnotes, blockquotes, and lists.

The renderer splits links block in three separate blocks, one
containing footnotes, the second containing images, and the third
links. Blocks are separated by a single line break.

This also makes the renderer skip link-only lists from rendering,
making them behave like links-only paragraphs (which are already
rendered as a series of consecutive links). The old behavior of
extracting links from links-only paragraphs (where the paragraph
itself is treated as just a set of links) remains, and can be still used.

The text extraction is also now unified across headings, paragraphs,
table headings, blockquotes, and other elements where it was used.
This fixes a number of bugs (like panicking on links inside headings)
and shortcomings where renderer would render text differently
based on container element type.

Fixes #17 and #23.
2021-09-03 20:48:32 +05:00
Timur Demin
ea62886fca
Implement footnotes support
This adds footnotes support, with rendering their text
after their parent paragraph. Footnotes are limited to
just one line by gomarkdown.

Fixes #16.
2021-08-31 10:12:39 +05:00
mntn
86faf01552
Add support for HR and super/sub-script
This makes the renderer write --- in place of
Markdown/HTML horizontal lines, and render super/subscript
as ^(superscript) and _{subscript} respectively.
2021-08-29 19:28:43 +05:00
mntn
ba767bc91f
Fix definition list rendering for multiple terms
The original implementation would incorrectly prefix the rest of the terms
if there were multiple terms going after each other (forming a list
themselves). 

Fixup f17a959fe2.
2021-08-28 09:33:55 +05:00
Timur Demin
f17a959fe2
Implement definition lists support
This adds the support of Markdown definition lists. The first item in
such lists (the definition itself) is printed without an item prefix.

Fixes #15.
2021-08-27 15:42:00 +05:00
Timur Demin
df6c035c7e
Refactor type detection code 2021-08-23 22:09:41 +03:00
Timur Demin
b4ae1981d6
Implement sort / sortRev in templates
This adds generic sort / sortRev functions for use in gmnhg templates
which use sort.Sort to sort anything that implements sort.Interface
(which includes lists of posts).

The existing sortPosts function that used to sort posts in reverse order
becomes an alias to sortRev for backwards compatibility.
2021-08-22 17:52:19 +03:00
mntn
5265bb6a25 Print delimiters around unsupported formatted elements 2021-08-22 14:31:39 +03:00
mntn
d3e8276e6e Add info string for fenced code blocks 2021-08-22 14:31:39 +03:00
Timur Demin
36922b6e95
Keep line breaks in blockquotes
This makes the renderer preserve existing line breaks in blockquotes,
provided they do not split paragraphs. Some clients/sites may use this
to form semantic around line breaks (for instance, for poems).

See #5.
2021-08-13 09:50:21 +05:00
Timur Demin
845bfa7cb2
Fix panic on empty blockquotes
While renderer previously assumed there would always be a single
paragraph inside the blockquote, there sometimes can be either more or
none.

See #5.
2021-08-13 08:52:52 +05:00
Timur Demin
e5d791165d Implement tables rendering
This adds support for Markdown table rendering with
github.com/olekukonko/tablewriter. Tables are rendered as ASCII text
in a preformatted text block. Cells are hard-aligned with spaces.
tablewriter options are not yet configurable, although they should be.
For now, extra formatting inside tables is omitted.

Fixes #2.
2021-08-09 20:13:10 +05:00
Timur Demin
0be85fc7f9
Handle H4-H6 in accordance with Gemini spec
Unlike Markdown, which has 6 levels of headings, Gemini spec (p. 5.5.1)
only allows up to 3 shebang characters before a space. This adds an extra
space before levels 4-6 in order to comply with the spec.

Fixes #1.
2021-08-09 12:00:48 +05:00
Timur Demin
1f5257ac90
Fix rendering of links-only paragraphs 2020-11-20 03:59:45 +05:00
Timur Demin
8c1a9a36da
Refactor rendering code
This refactoring simplifies some originally quirky parts of rendering
code while also adding support for rendering emphasized text (handled by
the same routine the ordinary text already is).
2020-11-19 03:09:28 +05:00
Timur Demin
35b4168935
Comply with Gemini spec p. 5.4.1
This part of spec says soft text wrapping is preferred to hard wrapping,
to comply with that we replace the newlines in raw Markdown text with
spaces.
2020-11-11 23:21:17 +05:00
Timur Demin
ceed6f07f4
Fix rendering of links as first paragraph child
Fixes #2.
2020-11-11 23:21:17 +05:00
Timur Demin
b181afc5f1
Add YAML front matter parsing support
Fixes #1. Only a subset of Hugo front matter props are supported, namely
title/date.
2020-11-11 23:21:17 +05:00
Timur Demin
326dc63112
Add support for inline code blocks 2020-11-11 23:21:17 +05:00
Timur Demin
32ec381d73
Add README and license code under GPLv3 2020-11-11 23:21:16 +05:00
Timur Demin
5de6b9b930
Add support for lists 2020-11-08 16:40:49 +05:00
Timur Demin
b2a941bdb6
Add preformatted text block support 2020-11-08 01:07:53 +05:00
Timur Demin
6ee9efab52
Improve the rendering of subsequent links 2020-11-08 00:05:53 +05:00
Timur Demin
3d9314f0a4
Make blockquote read stuff not byte-by-byte 2020-11-07 19:27:55 +05:00
Timur Demin
4799b2b511
Improve newline handling 2020-11-07 19:22:31 +05:00
Timur Demin
49725d712a
Add image/link text render and blockquote support 2020-11-07 17:21:36 +05:00
Timur Demin
85b0ef51b3
Add the latest code 2020-11-06 13:47:02 +05:00