Commit graph

278 commits

Author SHA1 Message Date
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
6dd8e90bb8 Cleanup: UPDATE README & Makefile
render hasn't been used for a long time now - time to get rid of it.
2019-01-07 20:31:12 +01:00
Niklas Fasching
2cf09dcf03 Fix AST headline nesting
Headlines are nested if their level is higher (more stars) than the current
headline. We're abusing the token.lvl field for this - as headlines can never
be indented we know the indentation must be 0 so we can cache the lvl (count of
stars) of the headline in that field.

This doesn't change anything right now so I'll postpone adding tests and stuff
until there are actual use cases for the AST and stuff.
2019-01-07 20:26:27 +01:00
Niklas Fasching
63fef04fb3 Add support for timestamps 2019-01-06 21:01:47 +01:00
Niklas Fasching
bd33e8885e Add String() method to Node interface
Being able to very easily get the original [1] Org mode content seems like
something that will come up quite often and is very little code.

[1] it's not really the original content, but rather the pretty printed version
of that - as the semantics don't change it shouldn't matter.
2019-01-06 20:50:02 +01:00
Niklas Fasching
148eef5aeb Refactor: Move some code
Example nodes are a kind of block and it's not much code so we can just put it
next to the Block code. Feels cleaner but doesn't change much.
2019-01-06 20:49:49 +01:00
Niklas Fasching
edd22b5014 Update README 2019-01-05 13:05:27 +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
7110853eb5 Fix fuzz 2019-01-02 21:22:13 +01:00
Niklas Fasching
56ecb2d401 Add some documentation & split Document into Configuration+Document 2019-01-02 19:17:17 +01:00
Niklas Fasching
c98cdea4f0 Improve document.GetOption: Merge default and buffer local options
Unlike the other BufferSettings, #+OPTIONS: specifies multiple options and we
cannot just look it up in either BufferSettings or DefaultSettings - both have
to be checked
2019-01-02 18:52:03 +01:00
Niklas Fasching
f62a00863f Remove FrontMatter
After giving it some thought I don't think this belongs in go-org - there's
just no use for it outside of hugo front matter handling
2019-01-02 18:34:40 +01:00
Niklas Fasching
348f697b41 Make Writer interface methods public: Allow other implementations 2019-01-02 18:34:40 +01:00
Niklas Fasching
fb39e59e6b Cleanup: Remove unused Document.StatusKeywords field & clean len checks
Leftover from the days before BufferSettings & DefaultSettings - now that those
exists the status keywords are actually defined in
- DefaultSettings["TODO"] for the default
- BufferSettings["TODO"] for any customizations

Also ! i < len => i >= len because it's easier on the eyes
2019-01-02 18:34:38 +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
940b1c7125 Fix outline nesting
oops - that got lost during the rebase - here we go
2018-12-26 17:44:01 +01:00
Niklas Fasching
141d6a27a9 Update README 2018-12-26 17:31:59 +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
Niklas Fasching
d921a68a55 Add support for Table of Contents 2018-12-26 16:10:23 +01:00
Niklas Fasching
eb7db9b968 Improve footnote handling
- Footnotes separator rather than headline to get around i18n
- Warn on footnote redefinition
- Do not export footnote definitions at point of definition, only in the
  footnote section.
- Do not automatically exclude Footnotes section to get around possibly hiding
  other content of such a section - and i18n.
  The user has the choice of explicitly hiding the section via a :noexport:
  tag.

and some other refactoring
2018-12-26 15:42:12 +01:00
Niklas Fasching
beff0c0d8a Add support for EXCLUDE_TAGS and :noexport: 2018-12-26 15:31:48 +01:00
Niklas Fasching
c3d635eacb Add more test cases 2018-12-21 16:05:38 +01:00
Niklas Fasching
c7c46ca1d9 Add MIT License
because I guess that's required for adding this for hugo (???)
2018-12-20 20:30:14 +01:00
Niklas Fasching
e8b90ab9d4 Update README 2018-12-20 16:49:26 +01:00
Niklas Fasching
854f8e181a Improve fuzzing function
We not only want to prevent panics, we also want rendering org -> org to not
change the meaning of the file. One easy way to check that (for the
nodes that print to html) whether that holds is to compare the html output.
2018-12-20 15:52:51 +01:00
Niklas Fasching
bc9c496f97 Misc cleanup: SETUP_FILE -> SETUPFILE, empty example lines, ... 2018-12-20 15:43:16 +01:00
Niklas Fasching
d1054063cf Anchor inline regexps and improve sub/super-script
The regexps are meant to extract a match immediately following the cursor - the
anchor should have been there from the beginning...

Also empty sub/superscript doesn't make sense - nested sub/superscript does
make sense but yagni.
2018-12-20 15:43:16 +01:00
Niklas Fasching
ab9d87fbc8 Clean up regexps 2018-12-20 15:43:16 +01:00
Niklas Fasching
36436a4c59 Fix inline parser unanchored regexps
fuzzed
2018-12-20 15:43:02 +01:00
Niklas Fasching
8e154c2fd8 Set up fuzzing with go-fuzz 2018-12-20 00:30:58 +01:00
Niklas Fasching
7a8e90f786 Improve logging and error handling
- enable logging by default: debug was a bad name - it's error logging that I
  just want to hide in tests
- don't panic (all the time)
- use a logger. this allows us to add more information - like the path of the
  parsed file!
2018-12-19 20:25:16 +01:00
Niklas Fasching
c23f8cc281 Add support for SETUP_FILE 2018-12-19 19:58:25 +01:00
Niklas Fasching
3ccbbc46ff Fix document parse() error handling
D'oh - I forgot to set the returned *Document when we panic.
2018-12-19 19:58:25 +01:00
Niklas Fasching
cbcdd4f923 Refactor: Move todoKeywords into parseHeadline
because.
2018-12-19 19:57:50 +01:00
Niklas Fasching
3709d1dc9c Revert "html: Export "#+HUGO: more" as <!--more-->"
This reverts commit 16a978fe48.

not needed after all - turns out hugo looks for the divider before rendering so
we can't do anything in go-org
2018-12-19 19:34:04 +01:00
Niklas Fasching
2295594970 Refactor FrontMatter parsing to better fit hugo requirements 2018-12-19 19:34:04 +01:00
Niklas Fasching
724cf6c23e Support list items with empty first line
also dismiss implementing ordered list bullet overrides for now, e.g.
1. [@10] foo

add it once someone needs it - for now it seems like needless complexity
2018-12-19 17:40:47 +01:00
Niklas Fasching
4e536f44bd Terminate descriptive list when list kind (ordered, unordered) changes 2018-12-19 17:34:46 +01:00
Niklas Fasching
1744ea100b Fix github pages
Oh bash...

Without this links all had the .sections styling and were put on a separate
line.
2018-12-19 14:59:31 +01:00
Niklas Fasching
ff9c077f65 Update README 2018-12-19 14:35:55 +01:00
Niklas Fasching
aa42998dbc Add support for headline CUSTOM_ID property & linking
this introduces the PropertyDrawer node to make it easier to access the
properties associated to a headline - normal drawers don't parse their content
into kv pairs
2018-12-19 14:31:07 +01:00
Niklas Fasching
ec895cbe83 Fix headline tags, table pretty printing and multiline links
- we can't just look at the len of the string (~ #bytes) - that breaks down for
  tables containing characters consisting of multiple bytes. This handles
  more (still not all) cases and is good enough for now
- add _ to allowed tag chars - also require space between headline and tags
- links (link itself, not the description) spanning multiple lines are not
  supported - otherwise we would have to take care of splitting link and adding
  indentation for org pretty printing - and that sounds like such an edge case
  that it seems cleaner to forbid them
2018-12-19 13:15:31 +01:00
Niklas Fasching
fb837e04af Fix parsing of regular links enclosed in [] 2018-12-19 12:24:02 +01:00
Niklas Fasching
905648c34b org: Fix drawer & block
- drawer entries without value were printed as FOO rather than :FOO:
- account for differences between raw & non-raw block:
  raw blocks are not wrapped in a further element, just raw text & line breaks:
  -> the first line has to be indented manually
  non raw blocks do not end in a linebreak newline -> the END_BLOCK line has to
  be indented (rather they end with a manual newline from another element)
2018-12-19 12:21:25 +01:00
Niklas Fasching
5f7d28f504 html: Handle bad usages of ATTR_HTML gracefully
log for debugging but do not panic
2018-12-19 11:43:35 +01:00
Niklas Fasching
788e466ab1 Match goorgeous frontmatter parsing behaviour 2018-12-19 01:07:22 +01:00
Niklas Fasching
16a978fe48 html: Export "#+HUGO: more" as <!--more--> 2018-12-19 01:07:22 +01:00
Niklas Fasching
144f2ce84f Trim space around keyword values 2018-12-19 01:07:22 +01:00