diff options
author | Alec Theriault <alec.theriault@gmail.com> | 2018-07-07 19:46:17 -0700 |
---|---|---|
committer | Alec Theriault <alec.theriault@gmail.com> | 2018-11-06 12:03:24 -0800 |
commit | 59be4f386c3803aeab7a9b2bc9bca49f1fe113db (patch) | |
tree | 1782131eb9d6654a7d0bfa38263528ec09d3c3f4 /haddock-library/src/Documentation/Haddock/Markup.hs | |
parent | 566536d6a1db7959197bed086c07cd23457ca378 (diff) |
Support (and flatten) inline markup in image links
Inline markup is supported in image links but, as per the [commonmark
recommendation][0], it is stripped back to a plain text representation.
[0]: https://spec.commonmark.org/0.28/#example-547
Diffstat (limited to 'haddock-library/src/Documentation/Haddock/Markup.hs')
-rw-r--r-- | haddock-library/src/Documentation/Haddock/Markup.hs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/haddock-library/src/Documentation/Haddock/Markup.hs b/haddock-library/src/Documentation/Haddock/Markup.hs index b581a4d2..b44fef80 100644 --- a/haddock-library/src/Documentation/Haddock/Markup.hs +++ b/haddock-library/src/Documentation/Haddock/Markup.hs @@ -2,10 +2,13 @@ module Documentation.Haddock.Markup ( markup , idMarkup + , plainMarkup ) where import Documentation.Haddock.Types +import Data.Maybe ( fromMaybe ) + markup :: DocMarkupH mod id a -> DocH mod id -> a markup m DocEmpty = markupEmpty m markup m (DocAppend d1 d2) = markupAppend m (markup m d1) (markup m d2) @@ -63,3 +66,34 @@ idMarkup = Markup { markupHeader = DocHeader, markupTable = DocTable } + +-- | Map a 'DocH' into a best estimate of an alternate string. The idea is to +-- strip away any formatting while preserving as much of the actual text as +-- possible. +plainMarkup :: (mod -> String) -> (id -> String) -> DocMarkupH mod id String +plainMarkup plainMod plainIdent = Markup { + markupEmpty = "", + markupString = id, + markupParagraph = id, + markupAppend = (<>), + markupIdentifier = plainIdent, + markupIdentifierUnchecked = plainMod, + markupModule = id, + markupWarning = id, + markupEmphasis = id, + markupBold = id, + markupMonospaced = id, + markupUnorderedList = const "", + markupOrderedList = const "", + markupDefList = const "", + markupCodeBlock = id, + markupHyperlink = \(Hyperlink url lbl) -> fromMaybe url lbl, + markupAName = id, + markupPic = \(Picture uri title) -> fromMaybe uri title, + markupMathInline = id, + markupMathDisplay = id, + markupProperty = id, + markupExample = const "", + markupHeader = \(Header _ title) -> title, + markupTable = const "" + } |