support definition lists

This commit is contained in:
Michael Teichgräber 2010-12-13 19:36:35 +01:00
parent 62502ab7a8
commit 1d57ae66a5
4 changed files with 86 additions and 3 deletions

View File

@ -71,6 +71,25 @@ See the [original README][] for details.
[original README]: https://github.com/jgm/peg-markdown/blob/master/README.markdown [original README]: https://github.com/jgm/peg-markdown/blob/master/README.markdown
[knieriem/peg]: https://github.com/knieriem/peg [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 (`<dd>...</dd>`) 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 ## Todo
* Implement definition lists (work in progress), and perhaps tables * Implement definition lists (work in progress), and perhaps tables

19
misc/func-name2line.rc Normal file
View File

@ -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
}
'

View File

@ -199,6 +199,12 @@ func (w *htmlOut) elem(elt *element, obfuscate bool) *htmlOut {
w.pad(2).s("<ul>").pset(0).elist(elt.children, obfuscate).pad(1).s("</ul>").pset(0) w.pad(2).s("<ul>").pset(0).elist(elt.children, obfuscate).pad(1).s("</ul>").pset(0)
case ORDEREDLIST: case ORDEREDLIST:
w.pad(2).s("<ol>").pset(0).elist(elt.children, obfuscate).pad(1).s("</ol>").pset(0) w.pad(2).s("<ol>").pset(0).elist(elt.children, obfuscate).pad(1).s("</ol>").pset(0)
case DEFINITIONLIST:
w.pad(2).s("<dl>").pset(0).elist(elt.children, obfuscate).pad(1).s("</dl>").pset(0)
case DEFTITLE:
w.pad(1).s("<dt>").pset(2).elist(elt.children, obfuscate).s("</dt>").pset(0)
case DEFDATA:
w.pad(1).s("<dd>").pset(2).elist(elt.children, obfuscate).s("</dd>").pset(0)
case LISTITEM: case LISTITEM:
w.pad(1).s("<li>").pset(2).elist(elt.children, obfuscate).s("</li>").pset(0) w.pad(1).s("<li>").pset(2).elist(elt.children, obfuscate).s("</li>").pset(0)
case BLOCKQUOTE: case BLOCKQUOTE:

View File

@ -84,6 +84,9 @@ const (
HRULE HRULE
REFERENCE REFERENCE
NOTE NOTE
DEFINITIONLIST
DEFTITLE
DEFDATA
numVAL numVAL
) )
@ -114,6 +117,7 @@ Block = BlankLine*
| Reference | Reference
| HorizontalRule | HorizontalRule
| Heading | Heading
| DefinitionList
| OrderedList | OrderedList
| BulletList | BulletList
| HtmlBlock | HtmlBlock
@ -191,7 +195,7 @@ BulletList = &Bullet (ListTight | ListLoose)
ListTight = a:StartList ListTight = a:StartList
( ListItem { a = cons($$, a) } )+ ( ListItem { a = cons($$, a) } )+
BlankLine* !(Bullet | Enumerator) BlankLine* !(Bullet | Enumerator | DefMarker)
{ $$ = mk_list(LIST, a) } { $$ = mk_list(LIST, a) }
ListLoose = a:StartList ListLoose = a:StartList
@ -203,7 +207,7 @@ ListLoose = a:StartList
} )+ } )+
{ $$ = mk_list(LIST, a) } { $$ = mk_list(LIST, a) }
ListItem = ( Bullet | Enumerator ) ListItem = ( Bullet | Enumerator | DefMarker )
a:StartList a:StartList
ListBlock { a = cons($$, a) } ListBlock { a = cons($$, a) }
( ListContinuationBlock { a = cons($$, a) } )* ( ListContinuationBlock { a = cons($$, a) } )*
@ -235,7 +239,7 @@ Enumerator = NonindentSpace [0-9]+ '.' Spacechar+
OrderedList = &Enumerator (ListTight | ListLoose) OrderedList = &Enumerator (ListTight | ListLoose)
{ $$.key = ORDEREDLIST } { $$.key = ORDEREDLIST }
ListBlockLine = !( Indent? (Bullet | Enumerator) ) ListBlockLine = !( (Indent? (Bullet | Enumerator)) | DefMarker )
!BlankLine !BlankLine
!HorizontalRule !HorizontalRule
OptionallyIndentedLine OptionallyIndentedLine
@ -744,6 +748,38 @@ RawNoteBlock = a:StartList
$$.key = RAW $$.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", HRULE: "HRULE",
REFERENCE: "REFERENCE", REFERENCE: "REFERENCE",
NOTE: "NOTE", NOTE: "NOTE",
DEFINITIONLIST: "DEFINITIONLIST",
DEFTITLE: "DEFTITLE",
DEFDATA: "DEFDATA",
} }