Commit 7a6a7728 authored by Henrik Tramberend's avatar Henrik Tramberend
Browse files

Add options for markdown write back

parent 1155ea64
......@@ -496,12 +496,12 @@ blockToMarkdown' opts b@(RawBlock f str)
| otherwise = do
report $ BlockNotRendered b
return empty
{-
blockToMarkdown' opts HorizontalRule = do
return $ blankline <> text (replicate (writerColumns opts) '-') <> blankline
-}
{-
blockToMarkdown' _ HorizontalRule = do
return $ blankline <> text "------" <> blankline
-}
blockToMarkdown' opts (Header level attr inlines) = do
-- first, if we're putting references at the end of a section, we
-- put them here.
......@@ -613,37 +613,15 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
| otherwise -> widths
(nst,tbl) <-
case True of
_ | isSimple &&
isEnabled Ext_simple_tables opts -> do
rawHeaders <- padRow <$> mapM (blockListToMarkdown opts) headers
rawRows <- mapM (fmap padRow . mapM (blockListToMarkdown opts))
rows
(nest 2,) <$> pandocTable opts False (all null headers)
aligns' widths' rawHeaders rawRows
| isSimple &&
_ | hasSimpleCells &&
isEnabled Ext_pipe_tables opts -> do
rawHeaders <- padRow <$> mapM (blockListToMarkdown opts) headers
rawRows <- mapM (fmap padRow . mapM (blockListToMarkdown opts))
rows
(id,) <$> pipeTable (all null headers) aligns' rawHeaders rawRows
| not hasBlocks &&
isEnabled Ext_multiline_tables opts -> do
rawHeaders <- padRow <$> mapM (blockListToMarkdown opts) headers
rawRows <- mapM (fmap padRow . mapM (blockListToMarkdown opts))
rows
(nest 2,) <$> pandocTable opts True (all null headers)
aligns' widths' rawHeaders rawRows
| isEnabled Ext_grid_tables opts &&
writerColumns opts >= 8 * numcols -> (id,) <$>
gridTable opts blockListToMarkdown
| isEnabled Ext_grid_tables opts -> (id,) <$>
gridTable opts{writerWrapText=WrapNone} blockListToMarkdown
(all null headers) aligns' widths' headers rows
-- Never write raw html tables
| hasSimpleCells &&
isEnabled Ext_pipe_tables opts -> do
rawHeaders <- padRow <$> mapM (blockListToMarkdown opts) headers
rawRows <- mapM (fmap padRow . mapM (blockListToMarkdown opts))
rows
(id,) <$> pipeTable (all null headers) aligns' rawHeaders rawRows
| otherwise -> return $ (id, text "[TABLE]")
return $ nst $ tbl $$ caption'' $$ blankline
blockToMarkdown' opts (BulletList items) = do
......
......@@ -12,15 +12,20 @@ import Markdown
import Resources
import Slide
import Control.Lens
import Control.Monad
import Data.Maybe
import qualified Data.Text.IO as T
import System.Directory
import System.FilePath
import System.IO.Temp
import System.IO
import System.IO.Temp
import System.Random
import Text.Pandoc
import Text.Pandoc.Lens
import Text.Pandoc.Shared
import Text.Printf
import Text.Read
idDigits = 4
......@@ -42,21 +47,35 @@ randomAlphaNum = do
randomAlpha :: IO Char
randomAlpha = getStdRandom (randomR ('a', 'z'))
-- | Writes a pandoc document to a markdown file.
-- | Writes a pandoc document atoimically to a markdown file. It uses a modified
-- Markdown writer that produces more appropriately formatted documents.
writeToMarkdownFile :: FilePath -> Pandoc -> IO ()
writeToMarkdownFile filepath pandoc = do
template <- getResourceString $ "template" </> "deck.md"
let columns =
fromMaybe 80 $ readMaybe $ stringify $ pandoc ^? meta "write-back" .
_MetaMap .
at "line-columns" .
_Just .
_MetaInlines
let wrapOpt "none" = WrapNone
wrapOpt "preserve" = WrapPreserve
wrapOpt _ = WrapAuto
let wrap =
stringify $ pandoc ^? meta "write-back" . _MetaMap . at "line-wrap" .
_Just .
_MetaInlines
let extensions =
(disableExtension Ext_simple_tables .
disableExtension Ext_multiline_tables .
disableExtension Ext_grid_tables . enableExtension Ext_auto_identifiers)
enableExtension Ext_auto_identifiers)
pandocExtensions
let options =
def
{ writerTemplate = Just template
, writerExtensions = extensions
, writerWrapText = WrapAuto
, writerColumns = 999
, writerColumns = columns
, writerWrapText = wrapOpt wrap
, writerSetextHeaders = False
}
markdown <- runIO (Markdown.writeMarkdown options pandoc) >>= handleError
......
......@@ -511,7 +511,7 @@ readMetaMarkdown markdownFile = do
case combinedMeta of
(MetaMap m) -> do
versionCheck (Meta m)
case lookupMeta "decker-slide-ids" (Meta m) of
case lookupMeta "generate-ids" (Meta m) of
Just (MetaBool True) ->
liftIO $ writeToMarkdownFile markdownFile (Pandoc fileMeta fileBlocks)
-- markForWriteBack markdownFile (Pandoc fileMeta fileBlocks)
......@@ -545,7 +545,10 @@ readMarkdownOrThrow opts markdown =
-- the current include mechanism if slides have duplicate titles in separate
-- include files.
deckerPandocExtensions :: Extensions
deckerPandocExtensions = disableExtension Ext_auto_identifiers pandocExtensions
deckerPandocExtensions =
(disableExtension Ext_auto_identifiers .
disableExtension Ext_simple_tables . disableExtension Ext_multiline_tables)
pandocExtensions
pandocReaderOpts :: ReaderOptions
pandocReaderOpts = def {readerExtensions = deckerPandocExtensions}
......
---
decker-slide-ids: True
generate-ids: True
---
------
--------------------------------------------------------------------------------
# Included {#zaf7}
## From `include/something.md`
Inclusion is supposed to be transitive with respect to resolution of relative resource and include pathes.
Inclusion is supposed to be transitive with respect to resolution of relative
resource and include pathes.
![A simple metal material (Image taken from [CGG](https://tramberend.beuth-hochschule.de/course/sommer-2017/cgg/)).](06-metal.png){width="50%"}
![A simple metal material (Image taken from
[CGG](https://tramberend.beuth-hochschule.de/course/sommer-2017/cgg/)).](06-metal.png){width="50%"}
---
decker-slide-ids: True
generate-ids: True
history: True
subtitle: High Quality Slide Annotations
title: Sketch Pad
write-back:
line-columns: 80
line-wrap: auto
---
------
--------------------------------------------------------------------------------
# Automatic Slide Id Generation {#s5zu}
## Id Generation
- If meta data attribute `decker-slide-ids` is set
- If meta data attribute `generate-ids` is set
1. If a slide has an id, it is not changed
2. Otherwise a 4-digit id is generated
3. **The markdown source is written back to file**
......@@ -22,7 +25,7 @@ title: Sketch Pad
- Forces a rigid formatting of the slide source code
- Not everybody will like this
------
--------------------------------------------------------------------------------
# First Slide {#myslide-dont-touch}
......@@ -30,18 +33,67 @@ title: Sketch Pad
- It will not change during further id generation
- It can be used in links (See [two slides up](#s5zu)) as usual
------
--------------------------------------------------------------------------------
# {#j355}
- This slide has no header, but a generated id
------
--------------------------------------------------------------------------------
# Third Slide {#s5zu}
- This slide has a generated id
- It will not change during further id generation
- It can be used in links (See [two slides down](#myslide-dont-touch)) as usual
- It can be used in links (See [two slides down](#myslide-dont-touch)) as
usual
[:include](./include/something.md)
--------------------------------------------------------------------------------
# Markdown Table Writeback {#e9r1}
## Pipe Table with more than 100 columns
| 123456789 | 123456789 | 123456789 | 123456789 | 123456789 | 123456789 | 123456789 | 123456789 | 123456789 | 123456789 |
|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
| | | | | | | | | | |
--------------------------------------------------------------------------------
# Markdown Table Writeback {#e9r1}
## Grid Table with more than 100 columns
+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
| 123456789 | 123456789 | 123456789 | 123456789 | 123456789 | 123456789 | 123456789 | 123456789 | 123456789 | 123456789 |
+============+===========+===========+===========+===========+===========+===========+===========+===========+===========+
| - line 1 | | | | | | | | | |
| - line 2 | | | | | | | | | |
| - line 3 | | | | | | | | | |
+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
--------------------------------------------------------------------------------
# {#n1bq}
| | | |
|-----------------------------|-----------------------------|-----------------------------|
| ![](./include/06-metal.png) | ![](./include/06-metal.png) | ![](./include/06-metal.png) |
| ![](./include/06-metal.png) | ![](./include/06-metal.png) | ![](./include/06-metal.png) |
| ![](./include/06-metal.png) | ![](./include/06-metal.png) | ![](./include/06-metal.png) |
--------------------------------------------------------------------------------
# {#g4z3}
+-----------------------------+-----------------------------+-----------------------------+
| ![](./include/06-metal.png) | ![](./include/06-metal.png) | ![](./include/06-metal.png) |
+-----------------------------+-----------------------------+-----------------------------+
| ![](./include/06-metal.png) | - Grid Tables | ![](./include/06-metal.png) |
| | - Coole Sache | |
| | - Emacs kann das | |
+-----------------------------+-----------------------------+-----------------------------+
| ![](./include/06-metal.png) | ![](./include/06-metal.png) | ![](./include/06-metal.png) |
+-----------------------------+-----------------------------+-----------------------------+
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment