1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
# -*- tcl -*-
# Engine to convert a doctoc document into markdown formatted text
#
# Copyright (c) 2019 Andreas Kupries <andreas_kupries@sourceforge.net>
# Freely redistributable.
#
######################################################################
dt_source _toc_common.tcl
dt_source _text.tcl
dt_source _markdown.tcl
######################################################################
# Conversion specification.
# One-pass processing.
rename toc_postprocess {}
rename text_postprocess toc_postprocess
proc fmt_plain_text {text} {return {}}
################################################################
## Backend for Markdown markup
proc fmt_toc_begin {label title} {
MDCInit
set title "$label -- $title"
TextInitialize
MDComment "Table of contents [Provenance]"
MDCDone
SectTitle hdr $title
Text [Compose hdr]
CloseParagraph [Verbatim]
ListOpen
return
}
proc fmt_toc_end {} { return }
proc fmt_division_start {title symfile} {
Text [ALink $symfile $title]
CloseParagraph [Verbatim]
ListOpen
}
proc fmt_division_end {} {
ContextPop ;# Ref (a)
return
}
proc fmt_item {file label desc} {
Text "[ALink $file $label] $desc"
CloseParagraph [Verbatim]
return
}
proc fmt_comment {text} { return }
proc ListOpen {} {
ContextPush ;# Ref (a)
ContextNew Division {
# Indenting is done by replicating the outer ws-prefix.
set bullet "[WPrefix?] [IBullet]"
List! bullet $bullet "[BlankM $bullet] "
}
return
}
################################################################
|