From 1d57ae66a5b0f91c61b7a34f61d13c4ada353429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Teichgr=C3=A4ber?= Date: Mon, 13 Dec 2010 19:36:35 +0100 Subject: [PATCH] support definition lists --- README.markdown | 19 ++++++++++++++++++ misc/func-name2line.rc | 19 ++++++++++++++++++ output.go | 6 ++++++ parser.leg | 45 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 misc/func-name2line.rc diff --git a/README.markdown b/README.markdown index c206dfb..add552e 100644 --- a/README.markdown +++ b/README.markdown @@ -71,6 +71,25 @@ See the [original README][] for details. [original README]: https://github.com/jgm/peg-markdown/blob/master/README.markdown [knieriem/peg]: https://github.com/knieriem/peg + +## Extensions + +In addition to the extensions already present in peg-markdown, +this package also supports definition lists (option `-dlists`) +similar to the way they are described in the documentation of +[PHP Markdown Extra][]. + +Definitions (`
...
`) are implemented using [ListTight][] +and `ListLoose`, on which bullet lists and ordered lists are based +already. If there is an empty line between the definition title and +the first definition, a loose list is expected, a tight list otherwise. + +As definition item markers both `:` and `~` can be used. + +[PHP Markdown Extra]: http://michelf.com/projects/php-markdown/extra/#def-list +[ListTight]: https://github.com/knieriem/markdown/blob/master/parser.leg#L191 + + ## Todo * Implement definition lists (work in progress), and perhaps tables diff --git a/misc/func-name2line.rc b/misc/func-name2line.rc new file mode 100644 index 0000000..8b58438 --- /dev/null +++ b/misc/func-name2line.rc @@ -0,0 +1,19 @@ +# print file and line number of closure func_$1 + +fnid=$1 +pkg=markdown + +account=github.com/knieriem +objpfx=$GOROOT/src/pkg/$account/+m/_obj +prj=$account +cmd=(info line $objpfx/$prj/$pkg._func_$fnid) +cmd=`{echo $cmd | sed 's,\.com,%2ecom,g'} +echo $cmd +gdb --batch --eval-command $"cmd ./cmd/markdown >[2] /dev/null | + grep '^Line.*of' | + awk ' + { + gsub("\"", "", $4) + print $4 ":" $2 + } +' diff --git a/output.go b/output.go index 7d33c5e..e8c7b17 100644 --- a/output.go +++ b/output.go @@ -199,6 +199,12 @@ func (w *htmlOut) elem(elt *element, obfuscate bool) *htmlOut { w.pad(2).s("").pset(0) case ORDEREDLIST: w.pad(2).s("
    ").pset(0).elist(elt.children, obfuscate).pad(1).s("
").pset(0) + case DEFINITIONLIST: + w.pad(2).s("
").pset(0).elist(elt.children, obfuscate).pad(1).s("
").pset(0) + case DEFTITLE: + w.pad(1).s("
").pset(2).elist(elt.children, obfuscate).s("
").pset(0) + case DEFDATA: + w.pad(1).s("
").pset(2).elist(elt.children, obfuscate).s("
").pset(0) case LISTITEM: w.pad(1).s("
  • ").pset(2).elist(elt.children, obfuscate).s("
  • ").pset(0) case BLOCKQUOTE: diff --git a/parser.leg b/parser.leg index c045982..d4773e2 100644 --- a/parser.leg +++ b/parser.leg @@ -84,6 +84,9 @@ const ( HRULE REFERENCE NOTE + DEFINITIONLIST + DEFTITLE + DEFDATA numVAL ) @@ -114,6 +117,7 @@ Block = BlankLine* | Reference | HorizontalRule | Heading + | DefinitionList | OrderedList | BulletList | HtmlBlock @@ -191,7 +195,7 @@ BulletList = &Bullet (ListTight | ListLoose) ListTight = a:StartList ( ListItem { a = cons($$, a) } )+ - BlankLine* !(Bullet | Enumerator) + BlankLine* !(Bullet | Enumerator | DefMarker) { $$ = mk_list(LIST, a) } ListLoose = a:StartList @@ -203,7 +207,7 @@ ListLoose = a:StartList } )+ { $$ = mk_list(LIST, a) } -ListItem = ( Bullet | Enumerator ) +ListItem = ( Bullet | Enumerator | DefMarker ) a:StartList ListBlock { a = cons($$, a) } ( ListContinuationBlock { a = cons($$, a) } )* @@ -235,7 +239,7 @@ Enumerator = NonindentSpace [0-9]+ '.' Spacechar+ OrderedList = &Enumerator (ListTight | ListLoose) { $$.key = ORDEREDLIST } -ListBlockLine = !( Indent? (Bullet | Enumerator) ) +ListBlockLine = !( (Indent? (Bullet | Enumerator)) | DefMarker ) !BlankLine !HorizontalRule OptionallyIndentedLine @@ -744,6 +748,38 @@ RawNoteBlock = a:StartList $$.key = RAW } + +DefinitionList = &{ p.extension.Dlists } + a:StartList + ( Definition { a = cons($$, a) } )+ + { $$ = mk_list(DEFINITIONLIST, a) } + +Definition = &( (!Defmark RawLine)+ BlankLine? Defmark) + a:StartList + ( DListTitle { a = cons($$, a) } )+ + ( DefTight | DefLoose ) { + for e := $$.children; e != nil; e = e.next { + e.key = DEFDATA + } + a = cons($$, a) + } + { $$ = mk_list(LIST, a) } + +DListTitle = NonindentSpace !Defmark &Nonspacechar + a:StartList + (!Endline Inline { a = cons($$, a) } )+ + Sp Newline + { $$ = mk_list(LIST, a) + $$.key = DEFTITLE + } + +DefTight = &Defmark ListTight +DefLoose = BlankLine &Defmark ListLoose + +Defmark = NonindentSpace (':' | '~') Spacechar+ +DefMarker = &{ p.extension.Dlists } Defmark + + %% @@ -963,4 +999,7 @@ var keynames = [numVAL]string{ HRULE: "HRULE", REFERENCE: "REFERENCE", NOTE: "NOTE", + DEFINITIONLIST: "DEFINITIONLIST", + DEFTITLE: "DEFTITLE", + DEFDATA: "DEFDATA", }