support definition lists
This commit is contained in:
parent
62502ab7a8
commit
1d57ae66a5
@ -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 (`<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
|
||||
|
||||
* Implement definition lists (work in progress), and perhaps tables
|
||||
|
19
misc/func-name2line.rc
Normal file
19
misc/func-name2line.rc
Normal 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
|
||||
}
|
||||
'
|
@ -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)
|
||||
case ORDEREDLIST:
|
||||
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:
|
||||
w.pad(1).s("<li>").pset(2).elist(elt.children, obfuscate).s("</li>").pset(0)
|
||||
case BLOCKQUOTE:
|
||||
|
45
parser.leg
45
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",
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user