aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
AgeCommit message (Collapse)AuthorFilesLines
2020-03-15Use implicit Prelude (#6187)Albert Krewinkel1-2/+0
* Use implicit Prelude The previous behavior was introduced as a fix for #4464. It seems that this change alone did not fix the issue, and `stack ghci` and `cabal repl` only work with GHC 8.4.1 or newer, as no custom Prelude is loaded for these versions. Given this, it seems cleaner to revert to the implicit Prelude. * PandocMonad: remove outdated check for base version Only base versions 4.9 and later are supported, the check for `MIN_VERSION_base(4,8,0)` is therefore unnecessary. * Always use custom prelude Previously, the custom prelude was used only with older GHC versions, as a workaround for problems with ghci. The ghci problems are resolved by replacing package `base` with `base-noprelude`, allowing for consistent use of the custom prelude across all GHC versions.
2020-03-13Update copyright year (#6186)Albert Krewinkel1-1/+1
* Update copyright year * Copyright: add notes for Lua and Jira modules
2020-02-08Factor out a findM function (#6125)Joseph C. Sible1-0/+9
This adds a new function to the API: Text.Pandoc.Shared.findM.
2020-02-07Apply linter suggestions. Add fix_spacing to lint target in Makefile.John MacFarlane1-9/+9
2020-02-07Resolve HLint warningsAlbert Krewinkel1-2/+0
All warnings are either fixed or, if more appropriate, HLint is configured to ignore them. HLint suggestions remain. * Ignore "Use camelCase" warnings in Lua and legacy code * Fix or ignore remaining HLint warnings * Remove redundant brackets * Remove redundant `return`s * Remove redundant as-pattern * Fuse mapM_/map * Use `.` to shorten code * Remove redundant `fmap` * Remove unused LANGUAGE pragmas * Hoist `not` in Text.Pandoc.App * Use fewer imports for `Text.DocTemplates` * Remove redundant `do`s * Remove redundant `$`s * Jira reader: remove unnecessary parentheses
2020-02-07Various minor cleanups and refactoring (#6117)Joseph C. Sible1-4/+3
* Use concatMap instead of reimplementing it * Replace an unnecessary multi-way if with a regular if * Use sortOn instead of sortBy and comparing * Use guards instead of lots of indents for if and else * Remove redundant do blocks * Extract common functions from both branches of maybe Whenever both the Nothing and the Just branch of maybe do the same function, do that function on the result of maybe instead. * Use fmap instead of reimplementing it from maybe * Use negative forms instead of negating the positive forms * Use mapMaybe instead of mapping and then using catMaybes * Use zipWith instead of mapping over the result of zip * Use unwords instead of reimplementing it * Use <$ instead of <$> and const * Replace case of Bool with if and else * Use find instead of listToMaybe and filter * Use zipWithM instead of mapM and zip * Inline lambda wrappers into the real functions * We get zipWithM from Text.Pandoc.Writers.Shared * Use maybe instead of fromMaybe and fmap I'm not sure how this one slipped past me. * Increase a bit of indentation
2019-12-17Improved makeSections so we don't get doubled attributes.John MacFarlane1-13/+17
Closes #5986.
2019-12-07Fix --toc-depth regression in 2.8.John MacFarlane1-6/+6
Closes #5967.
2019-12-05Roll back part of of `--shift-heading-level-by` change.John MacFarlane1-6/+0
With positive heading shifts, starting in 2.8 this option caused metadata titles to be removed and changed to regular headings. This behavior is incompatible with the old behavior of `--base-header-level` and breaks old workflows, so with this commit we are rolling back this change. Now, there is an asymmetry in positive and negative heading level shifts: + With positive shifts, the metadata title stays the same and does not get changed to a heading in the body. + With negative shifts, a heading can be converted into the metadata title. I think this is a desirable combination of features, despite the asymmetry. One might, e.g., want to have a document with level-1 section headigs, but render it to HTML with level-2 headings, retaining the metadata title (which pandoc will render as a level-1 heading with the default template). Closes #5957. Revises #5615.
2019-12-05Fix makeSections so it doesn't turn column divs into sections.John MacFarlane1-1/+3
2019-11-12Switch to new pandoc-types and use Text instead of String [API change].despresc1-118/+175
PR #5884. + Use pandoc-types 1.20 and texmath 0.12. + Text is now used instead of String, with a few exceptions. + In the MediaBag module, some of the types using Strings were switched to use FilePath instead (not Text). + In the Parsing module, new parsers `manyChar`, `many1Char`, `manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`, `mantyUntilChar` have been added: these are like their unsuffixed counterparts but pack some or all of their output. + `glob` in Text.Pandoc.Class still takes String since it seems to be intended as an interface to Glob, which uses strings. It seems to be used only once in the package, in the EPUB writer, so that is not hard to change.
2019-11-11Change the implementation of `htmlSpanLikeElements` and implement `<dfn>` ↵Florian Beeres1-1/+1
(#5882) * Add HTML Reader support for `<dfn>`, parsing this as a Span with class `dfn`. * Change `htmlSpanLikeElements` implementation to retain classes, attributes and inline content.
2019-10-29Shared.makeSections: better behavior in some corner cases.John MacFarlane1-3/+7
When a div surrounds multiple sections at the same level, or a section of highre level followed by one of lower level, then we just leave it as a div and create a new div for the section. Closes #5846, closes #5761.
2019-10-28Shared: improve isTight.John MacFarlane1-1/+1
If a list has an empty item, this should not count against its being a tight list. Closes #5857.
2019-10-16Add support for reading & writing <mark> elementsFlorian B1-1/+1
Parse <mark> elements from HTML as HTML span like elements, with a single class matching the tag name `mark`. Mark elements are rendered to HTML using the native <mark> element. Fixes https://github.com/jgm/pandoc/issues/5797.
2019-10-15Add support for reading and writing <kbd> elementsDaniele D'Orazio1-0/+6
* Text.Pandoc.Shared: export `htmlSpanLikeElements` [API change] This commit also introduces a mapping of HTML span like elements that are internally represented as a Span with a single class, but that are converted back to the original element by the html writer. As of now, only the kbd element is handled this way. Ideally these elements should be handled as plain AST values, but since that would be a breaking change with a large impact, we revert to this stop-gap solution. Fixes https://github.com/jgm/pandoc/issues/5796.
2019-10-11Fix `gfm_auto_identifiers` behavior with emojis.John MacFarlane1-1/+8
Closes #5813. Note that we also now use emoji names for emojis when `ascii_identifiers` is enabled.
2019-10-07Shored.camelCaseToHyphenated: handle ABCDef = abc-def.John MacFarlane1-2/+8
2019-09-19EPUB writer: improve splitting into chapters.John MacFarlane1-3/+6
+ Use makeSection from T.P.Shared. This deals better with embedded divs. (Closes #5761.) + Remove chapter-title class from chapter h1, for now. (Reverts one change made earlier; we may revisit this in light of #5749.) + Avoid issuing warning multiple times when title not set (see #5760).
2019-09-10Add --shift-heading-level-by option.John MacFarlane1-4/+17
Deprecate --base-heading-level. The new option does everything the old one does, but also allows negative shifts. It also promotes the document metadata (if not null) to a level-1 heading with a +1 shift, and demotes an initial level-1 heading to document metadata with a -1 shift. This supports converting documents that use an initial level-1 heading for the document title. Closes #5615.
2019-09-08Replace Element and makeHierarchical with makeSections.John MacFarlane1-61/+66
Text.Pandoc.Shared: + Remove `Element` type [API change] + Remove `makeHierarchicalize` [API change] + Add `makeSections` [API change] + Export `deLink` [API change] Now that we have Divs, we can use them to represent the structure of sections, and we don't need a special Element type. `makeSections` reorganizes a block list, adding Divs with class `section` around sections, and adding numbering if needed. This change also fixes some longstanding issues recognizing section structure when the document contains Divs. Closes #3057, see also #997. All writers have been changed to use `makeSections`. Note that in the process we have reverted the change c1d058aeb1c6a331a2cc22786ffaab17f7118ccd made in response to #5168, which I'm not completely sure was a good idea. Lua modules have also been adjusted accordingly. Existing lua filters that use `hierarchicalize` will need to be rewritten to use `make_sections`.
2019-09-08Revert changes to hierarchicalizeWithIds.John MacFarlane1-21/+5
Revert "hierarchicalize: ensure that sections get ids..." This reverts commit 212406a61d027d85712705e626954e0486a2bc34. Revert "Improve detection of headings in Divs by hierarchicalize." This reverts commit 6e2cfd6c97b1b8657f1f3e2b66090a2c3ba8d887. Revert "Shared.hierarchicalize: improve handling of div and section structure." This reverts commit 345b33762eb4cc6d57d74c76c4757a6166ee5c13.
2019-09-06hierarchicalize: ensure that sections get ids...John MacFarlane1-6/+10
even if they're in divs. Improves #3057.
2019-09-06Improve detection of headings in Divs by hierarchicalize.John MacFarlane1-1/+2
The structure ``` <h1>one</h1> <div> <h1>two</h1> </div> ``` should create two coordinate sections, not a section with a subsection. Now it does. Extends #3057.
2019-09-05Shared.hierarchicalize: improve handling of div and section structure.John MacFarlane1-4/+15
Previously Divs were opaque to hierarchicalize, so headings inside divs didn't get into the table of contents, for example (#3057). Now hierarchicalize treats Divs as sections when appropriate. For example, these structures both yield a section and a subsection: ``` html <div> <h1>one</h1> <div> <h2>two</h2> </div> </div> ``` ``` html <div> <h1>one</h1> <div> <h1>two</h1> </div> </div> ``` Note that ``` html <h1>one</h1> <div> <h2>two</h2> </div> <h1>three</h1> ``` gets parsed as the structure one two three which may not always be desirable. Closes #3057.
2019-08-25Use new doctemplates, doclayout.John MacFarlane1-1/+1
+ Remove Text.Pandoc.Pretty; use doclayout instead. [API change] + Text.Pandoc.Writers.Shared: remove metaToJSON, metaToJSON' [API change]. + Text.Pandoc.Writers.Shared: modify `addVariablesToContext`, `defField`, `setField`, `getField`, `resetField` to work with Context rather than JSON values. [API change] + Text.Pandoc.Writers.Shared: export new function `endsWithPlain` [API change]. + Use new templates and doclayout in writers. + Use Doc-based templates in all writers. + Adjust three tests for minor template rendering differences. + Added indentation to body in docbook4, docbook5 templates. The main impact of this change is better reflowing of content interpolated into templates. Previously, interpolated variables were rendered independently and intepolated as strings, which could lead to overly long lines. Now the templates interpolated as Doc values which may include breaking spaces, and reflowing occurs after template interpolation rather than before.
2019-07-16Make filterIpynbOutput strip ANSI escapes from code in output...John MacFarlane1-1/+10
for non-ipynb formats, when the default "best" option is used with --ipynb-output. The escape sequences cause problems in many formats, including LaTeX. Closes #5633.
2019-05-27consolidate simple-table detection (#5524)Mauro Bieg1-0/+15
add `onlySimpleTableCells` to `Text.Pandoc.Shared` [API change] This fixes an inconsistency in the HTML reader, which did not treat tables with `<p>` inside cells as simple.
2019-03-06filterIpynbOutput - go back to just including one block per format.John MacFarlane1-4/+3
In the end we need a 1-1 map of mime types to output blocks.
2019-03-06Fixed mistake in filterIpynbOutput (prefer lower, not higher rank!)John MacFarlane1-4/+3
2019-03-06Improve filterIpynbOutput.John MacFarlane1-4/+7
- Ensure that images are prioritized over text. - Allow multiple RawBlocks for same format.
2019-03-06Shared.filterIpynbOutput: 'best' should include everything for ipynb.John MacFarlane1-1/+5
2019-03-02Shared: remove withTempDir.John MacFarlane1-17/+0
2019-03-02Add new exported function defaultUserDataDirsJohn MacFarlane1-1/+17
2019-03-01Remove license boilerplate.John MacFarlane1-18/+0
The haddock module header contains essentially the same information, so the boilerplate is redundant and just one more thing to get out of sync.
2019-02-28Shared: add filterIpynbOutput. [API change]John MacFarlane1-1/+28
Add command line option `--ipynb-output=all|none|best`. Closes #5339.
2019-02-25Shared.compactify: Avoid mixed lists.John MacFarlane1-7/+6
This improves on the original fix to #5285 by preventing other mixed lists (lists with a mix of Plain and Para elements) that were allowed given the original fix.
2019-02-08Improve tight/loose list handling.John MacFarlane1-2/+9
Closes #5285. Previously the algorithm allowed list items with a mix of Para and Plain, which is never wanted. compactify in T.P.Shared has been modified so that, if a list's items contain (at the top level) Para elements (aside from perhaps at the very end), ALL Plains are converted to Paras.
2019-02-08Fix misleading code comment.John MacFarlane1-2/+1
2019-02-04Add missing copyright notices and remove license boilerplate (#5112)Albert Krewinkel1-2/+2
Quite a few modules were missing copyright notices. This commit adds copyright notices everywhere via haddock module headers. The old license boilerplate comment is redundant with this and has been removed. Update copyright years to 2019. Closes #4592.
2019-02-02Shared: withTempDir is no longer used in the codebase.John MacFarlane1-0/+2
Add comment to remove it in next major release.
2019-01-02Implement task lists (#5139)Mauro Bieg1-0/+32
Closes #3051
2018-11-19For bibliography match Div with id 'refs', not class 'references'.John MacFarlane1-2/+2
This was a mismatch between pandoc's docx, epub, latex, and markdown writers and the behavior of pandoc-citeproc, which actually looks for a div with id 'refs' rather than one with class 'references'.
2018-11-11Exactly match GitHub's identifier generating algorithm.John MacFarlane1-2/+7
See #5057.
2018-11-11Text.Pandoc.Shared: add parameter to uniqueIdent, inlineListToIdentifier.John MacFarlane1-22/+37
The parameter is Extensions. This allows these functions to be sensitive to the settings of `Ext_gfm_auto_identifiers` and `Ext_ascii_identifiers`. This allows us to use `uniqueIdent` in the CommonMark reader, replacing some custom code. It also means that `gfm_auto_identifiers` can now be used in all formats. Semantically, `gfm_auto_identifiers` is now a modifier of `auto_identifiers`; for identifiers to be set, `auto_identifiers` must be turned on, and then the type of identifier produced depends on `gfm_auto_identifiers` and `ascii_identifiers` are set. Closes #5057.
2018-11-03Add Text.Pandoc.Shared.ToString typeclass (API change)Alexander Krotov1-0/+12
2018-10-29LaTeX reader: allow space at end of math after `\`.John MacFarlane1-0/+10
Closes #5010. Expose trimMath from T.P.Shared.
2018-10-10Reimplement mapLeft using Bifunctor.firstAlexander Krotov1-2/+2
2018-10-01Shared: new export `splitSentences` [API change].John MacFarlane1-0/+26
This was duplicated in the Man and Ms writers, and really belongs in Shared.
2018-07-30Lua Utils module: add function blocks_to_inlines (#4799)Albert Krewinkel1-2/+11
Exposes a function converting which flattenes a list of blocks into a list of inlines. An example use case would be the conversion of Note elements into other inlines.