+ Improved text wrapping algorithm in markdown, docbook, and RST writers.
LineBreaks no longer cause ugly wrapping in Markdown output. + Replaced splitBySpace with the more general, polymorphic function splitBy (in Text/Pandoc/Shared). git-svn-id: https://pandoc.googlecode.com/svn/trunk@411 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
parent
e4880319e6
commit
99959b68e9
6 changed files with 28 additions and 13 deletions
7
debian/changelog
vendored
7
debian/changelog
vendored
|
@ -103,6 +103,8 @@ pandoc (0.3) unstable; urgency=low
|
|||
+ Modified HTML reader to skip a newline following a <br> tag.
|
||||
Otherwise the newline will be treated as a space at the beginning
|
||||
of the next line.
|
||||
+ Fixed bug in text-wrapping routine in Markdown and RST writers.
|
||||
Now LineBreaks no longer cause wrapping problems.
|
||||
|
||||
* Made handling of code blocks more consistent. Previously, some
|
||||
readers allowed trailing newlines, while others stripped them.
|
||||
|
@ -162,7 +164,8 @@ pandoc (0.3) unstable; urgency=low
|
|||
a '.exe' extension is added to each executable in EXECS.
|
||||
|
||||
* Removed all wrappers except markdown2pdf and html2markdown.
|
||||
Added new wrapper hsmarkdown, to be used as a drop-in replacement
|
||||
|
||||
* Added new wrapper hsmarkdown, to be used as a drop-in replacement
|
||||
for Markdown.pl. hsmarkdown calls pandoc with the '--strict'
|
||||
option and disables other options.
|
||||
|
||||
|
@ -185,6 +188,8 @@ pandoc (0.3) unstable; urgency=low
|
|||
not to be HTML-specific.
|
||||
+ Removed 'BlockQuoteContext' from ParserContext, as it isn't
|
||||
used anywhere.
|
||||
+ Removed splitBySpace and replaced it with a general, polymorphic
|
||||
splitBy function.
|
||||
+ Refactored LaTeX reader for clarity (added isArg function).
|
||||
+ Converted some CR's to LF's in src/ui/default/print.css.
|
||||
+ Added license text to top of source files.
|
||||
|
|
|
@ -52,7 +52,7 @@ module Text.Pandoc.Shared (
|
|||
-- * Pandoc block list processing
|
||||
consolidateList,
|
||||
isNoteBlock,
|
||||
splitBySpace,
|
||||
splitBy,
|
||||
normalizeSpaces,
|
||||
compactify,
|
||||
generateReference,
|
||||
|
@ -274,10 +274,13 @@ removeTrailingSpace = reverse . removeLeadingSpace . reverse
|
|||
stripFirstAndLast str =
|
||||
drop 1 $ take ((length str) - 1) str
|
||||
|
||||
-- | Split list of inlines into groups separated by a space.
|
||||
splitBySpace :: [Inline] -> [[Inline]]
|
||||
splitBySpace lst = filter (\a -> (/= Space) (head a))
|
||||
(groupBy (\a b -> (/= Space) a && (/= Space) b) lst)
|
||||
-- | Split list into groups separated by sep.
|
||||
splitBy :: (Eq a) => a -> [a] -> [[a]]
|
||||
splitBy _ [] = []
|
||||
splitBy sep lst =
|
||||
let (first, rest) = break (== sep) lst
|
||||
rest' = dropWhile (== sep) rest in
|
||||
first:(splitBy sep rest')
|
||||
|
||||
-- | Normalize a list of inline elements: remove leading and trailing
|
||||
-- @Space@ elements, and collapse double @Space@s into singles.
|
||||
|
|
|
@ -176,7 +176,7 @@ cdata str = text $ "<![CDATA[" ++ str ++ "]]>"
|
|||
|
||||
-- | Take list of inline elements and return wrapped doc.
|
||||
wrap :: WriterOptions -> [Inline] -> Doc
|
||||
wrap options lst = fsep $ map (hcat . (map (inlineToDocbook options))) (splitBySpace lst)
|
||||
wrap options lst = fsep $ map (inlinesToDocbook options) (splitBy Space lst)
|
||||
|
||||
-- | Escape a string for XML (with "smart" option if specified).
|
||||
stringToXML :: WriterOptions -> String -> String
|
||||
|
|
|
@ -58,8 +58,13 @@ escapeLinkTitle = gsub "\"" "\\\\\""
|
|||
|
||||
-- | Take list of inline elements and return wrapped doc.
|
||||
wrappedMarkdown :: [Inline] -> Doc
|
||||
wrappedMarkdown lst = fsep $
|
||||
map (fcat . (map inlineToMarkdown)) (splitBySpace lst)
|
||||
wrappedMarkdown lst =
|
||||
let wrapSection sec = fsep $ map inlineListToMarkdown $ (splitBy Space sec)
|
||||
wrappedSecs = map wrapSection $ splitBy LineBreak lst
|
||||
wrappedSecs' = foldr (\s rest -> if not (null rest)
|
||||
then (s <> text " "):rest
|
||||
else s:rest) [] wrappedSecs in
|
||||
vcat wrappedSecs'
|
||||
|
||||
-- | Insert Blank block between key and non-key
|
||||
formatKeys :: [Block] -> [Block]
|
||||
|
|
|
@ -59,9 +59,10 @@ escapeString = backslashEscape "`\\|*_"
|
|||
-- and another containing references.
|
||||
wrappedRST :: [Inline] -> (Doc, Doc)
|
||||
wrappedRST lst =
|
||||
let words = splitBySpace lst in
|
||||
( fsep $ map (fcat . (map (fst . inlineToRST))) words,
|
||||
vcat (map (snd . inlineToRST) lst) )
|
||||
let wrap_section sec = fsep $ map (fst . inlineListToRST) $
|
||||
(splitBy Space sec) in
|
||||
((vcat $ map wrap_section $ (splitBy LineBreak lst)),
|
||||
vcat $ map (snd . inlineToRST) lst)
|
||||
|
||||
-- | Remove reference keys, and make sure there are blanks before each list.
|
||||
reformatBlocks :: [Block] -> [Block]
|
||||
|
|
|
@ -55,7 +55,8 @@ looked like a list item.
|
|||
|
||||
Here's one with a bullet. \* criminey.
|
||||
|
||||
There should be a hard line break here.
|
||||
There should be a hard line break
|
||||
here.
|
||||
|
||||
--------------
|
||||
|
||||
|
|
Loading…
Reference in a new issue