Commit graph

21 commits

Author SHA1 Message Date
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
Niklas Fasching
5c51067b59 Rename files containing org and htm writer
The naming `org.go` is confusing as it's not the main class of the org package
2018-12-26 16:11:40 +01:00
Renamed from org/html.go (Browse further)