Commit graph

51 commits

Author SHA1 Message Date
Niklas Fasching
9995b3cdad html: Improve link abbreviation (#+LINK) resolution
Handle `%s`/`%h` interpolation and add support for shorthand of prefix only
links / links with empty tag (i.e. `[example]` instead of [example:]). See
[1] and [2]. As so often we don't match org mode output completely but our
output looks sane enough to me so let's move along for now.

[1] https://orgmode.org/manual/Link-Abbreviations.html
[2] https://github.com/bzg/org-mode/blob/main/lisp/ol.el#L1011
2021-10-25 16:50:15 +02:00
Niklas Fasching
c901c00166 Add non-standard ealb (east asian line break) option
See pandoc: https://pandoc.org/MANUAL.html#extension-east_asian_line_breaks
2021-07-20 22:33:28 +02:00
Ori
4d3a099922 For simple list items, don't wrap in <p> tags
This also removes extra newlines for simple list items, see changes to
tests for details.

Closes #57
2021-07-13 23:41:32 +02:00
Niklas Fasching
abb81851be html: Hide excluded headlines from TOC
emacs org mode did it first
2021-07-13 20:54:23 +02:00
Niklas Fasching
21f1af7d48 Add support for custom numbering of ordered list using [@\d+]
org mode supports [1] setting the value attribute [2] of ordered list items to
change the numbering for the current and following items. Let's do the same. As
the attribute has no meaning for other types of lists [2] we'll just not
support it for those cases [3].

[1] https://orgmode.org/manual/Plain-Lists.html#Plain-Lists
[2] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li#attributes
[3]
Org mode seems to instead set the id attribute for e.g. unordered lists
starting with `[@\d+]\s` - but I don't really see the value in that and will
skip that for now.
2021-04-17 15:43:19 +02:00
Niklas Fasching
7c239a7aeb html: Add support for #+TOC keyword
org mode allows rendering the toc anywhere in the html document using the `TOC`
keyword [1]. There's more options but `#+TOC: headlines $n` should be enough
for starters. Note that org mode still requires setting `#+OPTIONS: toc:nil` to
disable the default toc

[1] https://orgmode.org/manual/Table-of-Contents.html
2021-03-28 17:12:25 +02:00
Niklas Fasching
5dadf8c4c2 html: Support pretty relative links
Hugo defaults to serving files with pretty urls [1] - this means
`/posts/foo.org` is served at `/posts/foo/`. This works because servers
default to serving index.html when a directory is specified and hugo renders
the post to `/posts/foo/index.html` instead of `/posts/foo.html`. To make
relative links work we need to (1) remove the fake `foo/` subdirectory from
unrooted links and (2) replace any `.org` suffix with `/`.

[1] https://gohugo.io/content-management/urls/#pretty-urls
2021-01-02 20:48:28 +01:00
Niklas Fasching
84d56e9562 html: Rewrite local links to .org files to .html
emacs rewrites links to `.org` files to corresponding links with `.html`
extension in the html export.
2021-01-02 20:47:55 +01:00
Niklas Fasching
add727c011 html: Wrap headline+content & headline content in containers
Org mode does it.
2020-06-29 16:48:46 +02:00
Niklas Fasching
d85768891c html: Support links with image descriptions
Turns out Org mode supports image links natively and we don't have to go out of
spec!

From https://orgmode.org/manual/Images-in-HTML-export.html:

[...] if the description part of the Org link is itself another link, such as
‘file:’ or ‘http:’ URL pointing to an image, the HTML export back-end in-lines
this image and links to [...]
2020-06-28 21:16:46 +02:00
Niklas Fasching
e076412b29 html: Implement fat table rows (use tbodies to represent separators)
html does not support table separator rows as Org mode does. Emacs org export
simulates rows as defined by separators by wrapping all the rows between 2
separators into a separate tbody. The html spec is fine with that [0] so we
follow.

[0] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody
2020-06-26 20:11:14 +02:00
Niklas Fasching
a383eef7a6 html: Remove cosmetic whitespace inside p tags
All tags are put on a line by themselves to help with visual
diffing. Apparently this extra cosmetic whitespace causes problems inside p
tags for ppl who want to use `white-space: pre`. Not much hurt for visual
diffing in removing cosmetic whitespace for just p tags and can't think of
anything that would break because of this right now. So let's do it and wait
for things to break.
2020-06-26 18:55:15 +02:00
Niklas Fasching
5e50794af0 Add title export option
see https://orgmode.org/manual/Export-Settings.html
2020-06-26 12:25:17 +02:00
Niklas Fasching
9f7e8a8fbd Implement #+MACRO 2020-04-17 16:41:06 +02:00
Niklas Fasching
2ab65d300a Fix #+LINK: file xyz edge case
if we define a custom LINK for file we run into index problems bc it's trimmed
before already - this fixes that. Shouldn't ever happen but whatever, fuzzing
found it.
2020-04-17 16:18:33 +02:00
Niklas Fasching
1e36b3b46b Implement #+LINK 2020-04-17 15:59:03 +02:00
Niklas Fasching
7e69931976 html: Implement source block :exports parameter 2020-04-17 15:24:42 +02:00
Niklas Fasching
efe1c4eb07 html: Cleanup block name switch 2020-04-17 15:12:04 +02:00
Niklas Fasching
cd923ba41a Implement source block results
To support code block directives like :exports none we need context - i.e. we
need to have the block and it's results at once and can't just render them
independently.
2020-04-17 15:02:56 +02:00
Niklas Fasching
f6f4646d45 Implement result blocks 2020-04-17 14:54:02 +02:00
Niklas Fasching
232c27327c html: Fix inline source block highlighting & escaping 2020-04-16 16:22:36 +02:00
Niklas Fasching
cbf1b8c38c html: Allow inline html export in #+TITLE 2020-04-16 15:18:33 +02:00
Niklas Fasching
4b56810a65 Implement inline export blocks
https://orgmode.org/manual/Quoting-HTML-tags.html
2020-04-16 14:58:23 +02:00
Niklas Fasching
3018ace8d0 Implement inline source blocks
https://orgmode.org/manual/Structure-of-Code-Blocks.html
2020-04-16 14:58:13 +02:00
Niklas Fasching
6ed46ba95d html: Do not render non-html export blocks 2020-03-31 16:30:38 +02:00
Niklas Fasching
c68d931100 html: Fix example blocks - escape html
While example blocks do not render inline markup and are thus parsed raw in
some way, their contents are not literal html and thus still need to be html
escaped.
2020-03-31 16:30:28 +02:00
Niklas Fasching
f1361615ed html: Allow limiting level of headlines to be included in toc
The org mode toc OPTION does not just support true/false - it also allows
specifying the max headline level [1] to be included in the toc.

[1] headline level as seen in org mode - not the html tag level
2020-01-20 18:44:09 +01:00
Niklas Fasching
7a2cd1abb1 Refactor: Return string value from GetOption
Turns out org export options can have meaningful values beside true and false -
let's make it possible to use them.
2020-01-20 18:14:10 +01:00
Niklas Fasching
614307a8f5 HTML export: Export #+TITLE as h1 and offset other headlines accordingly
emacs exports #+TITLE as <h1> and all other headlines accordingly as
`lvl + 1` - we'll go with that.
2019-12-22 14:17:14 +01:00
Niklas Fasching
9a0a9c11eb Export WriteNodesAsString on writer interface
WriteNodesAsString is simple enough to implement but exposing it is helpful in
the implementation of extending writers and we don't aim to keep writer a small
interface so let's expose it.
2019-11-02 23:44:16 +01:00
Niklas Fasching
c9d11e1556 Refactor OrgWriter and HTMLWriter: Remove cloning
Extension of the org & html writers is made possible by creating circular
references between the extending and extended writer - that way the extending
writer can forward all methods it doesn't implement to the extended writer and the
extended writer can use the extending writer as the root for method calls to
make sure methods overridden in the extending writer are used even for nested
method calls.

This circular reference leads to problems when cloning writers - cloning the
extended writer merely copies the pointer to the extending writer - i.e. the
extending writer does not get cloned with an updated reference to the extended
writer. Thus method calls to the extending writer act as if no cloning took
place and things break.

The easiest solution is to just get rid of cloning. We could also clone the
ExtendingWriter and replace it's reference to the extended writer with the just
cloned one but that's harder so we just remove it.

As there are a lot of "extending writer" and "extended writer" in the above
paragraphs and I'm too lazy to write up something better here's another attempt
at a TLDR:

Cloning is broken as ExtendingWriter is a reference to a writer that has
a reference to the writer we are cloning - that writer would have to have it's
reference updated but that's hard. So we solve it it by not cloning at all.
2019-11-02 23:33:34 +01:00
Niklas Fasching
14900e97e2 Add support for extending writers
Go does not support inheritance, just composition. While composition with type
embedding (i.e. forwarding method calls to the embedded type) can replace
inheritance for most use cases this is not one of them. We really want to
overwrite methods so that method calls from inside the base writer also use the
custom methods ouf our extending writer - naive embedding does not work here
as the this in this.WriteText refers to the embedded type rather than the outer
extending type (see open recursion).

A simple solution is to make a reference of the extending type
available from the extended type and use that for nested method calls. We'll go
with that one as it does not require huge code changes. Another solution would
be to flatten the writing process and not use nested method calls - this is
what blackfriday does. Assuming the current solution works I feel it's cleaner
and keeps the ugliness of simulating inheritance with composition contained to
a small portion of the code while blackfridays approach requires all write
methods to be written in a flat style (i.e. not do nested calls to write by
being called twice with entering / leaving). The current solution becomes ugly
if we want to do multiple levels of extending but i don't expect that to be a
valid use case - if it turns out to be one we can always adapt to it
later. YAGNI.
2019-10-27 16:43:42 +01:00
Niklas Fasching
20970ec872 Add support for NAME keyword 2019-10-27 15:12:38 +01:00
Niklas Fasching
76b157b8ce Add support for latex fragments 2019-09-28 15:04:04 +02:00
Niklas Fasching
a143b04826 html: write descriptive list closing dt tag on separate line
now that i'm already looking at it due to the bug leenzhu found why not put the
</dt> on a separate line to match the convention - looks better to me; doesn't
change anything.
2019-08-26 14:37:52 +02:00
leen
9aec7ca151 WriteDescriptiveListItem() missing closing tags for dt and dd 2019-08-26 18:38:04 +08:00
Niklas Fasching
f67a251e27 html: Fix html writer footnotes (in headlines)
writer.footnotes must be a pointer as we copy the writer in nodesAsString() and
can thus end up modifying the footnotes.list slice without it being reflected in
the original writer (i.e. when the backing array of the slice changes).
2019-08-24 12:11:23 +02:00
Niklas Fasching
97fe8b7850 html: Fix code block export (superfluous newlines)
I didn't consider that all newlines in the pre block will be printed and we
thus shouldn't wrap html that has it's tags on separate lines (i.e. contains
superfluous newlines) - wrapping in a div less accurately represents
org-html-export but it provides the same information and gives us more freedom
in the return value of HighlightCodeBlock as well as allowing us to keep the
html tags on new lines (consistency).
2019-07-28 16:40:09 +02:00
Niklas Fasching
777899c803 HTML export: Update footnote numbering to start with 1
I went with 0 based numbering because it was easier but after looking at the
results 0 based numbering looks bad to me... let's start with 1 like everyone
else as it's just a few more lines of code.
2019-07-07 21:25:42 +02:00
Niklas Fasching
d154403f06 HTML export: Improve handling of missing footnote definitions 2019-07-07 18:01:22 +02:00
Niklas Fasching
37d33c1206 HTML export: Export src block language as css class
Org mode exports source blocks with the language as a css-class of the exported
source block - it's easy enough to do the same.
2019-07-07 10:19:24 +02:00
Niklas Fasching
6dc04b4b02 Refactor footnote handling
- Remove unused footnote section title option
- Move away from maintaining a list of footnotes in the document (only needed
  for html export, potential maintainance overhead when modifying the document)
  and rather only build it on export when required.
- HTML export: Rename all footnotes to numbers (so we can support anonymous
  footnote references by assigning them a number) and export footnotes in order
  of reference, not definition. The implementation of this makes it natural to
  also stop exporting unused footnote definitions so we do that as well.
2019-07-07 10:01:43 +02:00
Niklas Fasching
cec002db22 Improve NewHTMLWriter() defaults
HTMLWriter uses the document to look up export options and adapt it's
behaviour. The writer.document & log are set in the Before() method during
normal use via document.Write().

Sometimes the writer is used separately and won't have it's Before method
called - in those cases we should use the defaults rather than crashing.
2019-01-07 21:43:50 +01:00
Niklas Fasching
63fef04fb3 Add support for timestamps 2019-01-06 21:01:47 +01:00
Niklas Fasching
3e14771ebf Remove unnecessary type alias for strings.Builder
TIL embedded types can be acessed by their non-namespaced name - so there
actually is no need for a type alias to access .strings.Builder, one can just
use .Builder.
2019-01-05 13:04:21 +01:00
Niklas Fasching
faea88d48e Refactor Writer Interface
The existing approach made it hard to extend existing writers.
With this change, replacing individual methods of a writer is possible by
embedding it.

Sharing the WriteNodes function also removes some unnecesseray duplication, so
win win.
2019-01-04 20:13:42 +01:00
Niklas Fasching
56ecb2d401 Add some documentation & split Document into Configuration+Document 2019-01-02 19:17:17 +01:00
Niklas Fasching
348f697b41 Make Writer interface methods public: Allow other implementations 2019-01-02 18:34:40 +01:00
Niklas Fasching
d3d3b6c593 Fix table of contents for hugo
Hugo has some hardcoded checks that have to be fulfilled in its Table of
Contents extraction workflow (helpers/content ExtractTOC). It's easier this
way...
2018-12-26 18:53:31 +01:00
Niklas Fasching
d036ddea4d Add support for some #+OPTIONS toggles
see https://orgmode.org/manual/Export-settings.html
2018-12-26 16:58:16 +01:00