2010-11-21 22:04:39 +00:00
|
|
|
%{
|
|
|
|
/* Original C version https://github.com/jgm/peg-markdown/
|
|
|
|
* Copyright 2008 John MacFarlane (jgm at berkeley dot edu).
|
|
|
|
*
|
|
|
|
* Modifications and translation from C into Go
|
|
|
|
* based on markdown_parser.leg and utility_functions.c
|
|
|
|
* Copyright 2010 Michael Teichgräber (mt at wmipf dot de)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License or the MIT
|
|
|
|
* license. See LICENSE for details.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package markdown
|
|
|
|
|
|
|
|
// PEG grammar and parser actions for markdown syntax.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2012-04-21 21:08:33 +00:00
|
|
|
"io"
|
2010-11-21 22:04:39 +00:00
|
|
|
"log"
|
2013-01-23 20:51:00 +00:00
|
|
|
"strings"
|
2010-11-21 22:04:39 +00:00
|
|
|
)
|
|
|
|
|
2012-04-29 22:55:37 +00:00
|
|
|
const (
|
2012-04-30 08:16:52 +00:00
|
|
|
parserIfaceVersion_16 = iota
|
2012-04-29 22:55:37 +00:00
|
|
|
)
|
|
|
|
|
2010-11-21 22:04:39 +00:00
|
|
|
// Semantic value of a parsing action.
|
|
|
|
type element struct {
|
2013-01-23 20:51:00 +00:00
|
|
|
key int
|
2010-11-21 22:04:39 +00:00
|
|
|
contents
|
2013-01-23 20:51:00 +00:00
|
|
|
children *element
|
|
|
|
next *element
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Information (label, URL and title) for a link.
|
|
|
|
type link struct {
|
2013-01-23 20:51:00 +00:00
|
|
|
label *element
|
|
|
|
url string
|
|
|
|
title string
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Union for contents of an Element (string, list, or link).
|
|
|
|
type contents struct {
|
2013-01-23 20:51:00 +00:00
|
|
|
str string
|
2010-11-21 22:04:39 +00:00
|
|
|
*link
|
|
|
|
}
|
|
|
|
|
|
|
|
// Types of semantic values returned by parsers.
|
|
|
|
const (
|
2013-01-23 20:51:00 +00:00
|
|
|
LIST = iota /* A generic list of values. For ordered and bullet lists, see below. */
|
|
|
|
RAW /* Raw markdown to be processed further */
|
2010-11-21 22:04:39 +00:00
|
|
|
SPACE
|
|
|
|
LINEBREAK
|
|
|
|
ELLIPSIS
|
|
|
|
EMDASH
|
|
|
|
ENDASH
|
|
|
|
APOSTROPHE
|
|
|
|
SINGLEQUOTED
|
|
|
|
DOUBLEQUOTED
|
|
|
|
STR
|
|
|
|
LINK
|
|
|
|
IMAGE
|
|
|
|
CODE
|
|
|
|
HTML
|
|
|
|
EMPH
|
|
|
|
STRONG
|
|
|
|
PLAIN
|
|
|
|
PARA
|
|
|
|
LISTITEM
|
|
|
|
BULLETLIST
|
|
|
|
ORDEREDLIST
|
2013-01-23 20:51:00 +00:00
|
|
|
H1 /* Code assumes that H1..6 are in order. */
|
2010-11-21 22:04:39 +00:00
|
|
|
H2
|
|
|
|
H3
|
|
|
|
H4
|
|
|
|
H5
|
|
|
|
H6
|
|
|
|
BLOCKQUOTE
|
|
|
|
VERBATIM
|
|
|
|
HTMLBLOCK
|
|
|
|
HRULE
|
|
|
|
REFERENCE
|
|
|
|
NOTE
|
2010-12-13 18:36:35 +00:00
|
|
|
DEFINITIONLIST
|
|
|
|
DEFTITLE
|
|
|
|
DEFDATA
|
2010-11-21 22:04:39 +00:00
|
|
|
numVAL
|
|
|
|
)
|
|
|
|
|
2012-04-28 20:57:55 +00:00
|
|
|
type state struct {
|
2013-01-23 20:51:00 +00:00
|
|
|
extension Extensions
|
|
|
|
heap elemHeap
|
|
|
|
tree *element /* Results of parse. */
|
|
|
|
references *element /* List of link references found. */
|
|
|
|
notes *element /* List of footnotes found. */
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
2012-04-28 20:57:55 +00:00
|
|
|
%userstate state
|
|
|
|
|
|
|
|
%noexport
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
%YYSTYPE *element
|
|
|
|
|
|
|
|
Doc = a:StartList ( Block { a = cons($$, a) } )*
|
|
|
|
{ p.tree = reverse(a) }
|
|
|
|
commit
|
|
|
|
|
2012-04-28 20:57:55 +00:00
|
|
|
Docblock = Block { p.tree = $$ } commit
|
|
|
|
|
2010-11-21 22:04:39 +00:00
|
|
|
Block = BlankLine*
|
|
|
|
( BlockQuote
|
|
|
|
| Verbatim
|
|
|
|
| Note
|
|
|
|
| Reference
|
|
|
|
| HorizontalRule
|
|
|
|
| Heading
|
2010-12-13 18:36:35 +00:00
|
|
|
| DefinitionList
|
2010-11-21 22:04:39 +00:00
|
|
|
| OrderedList
|
|
|
|
| BulletList
|
|
|
|
| HtmlBlock
|
|
|
|
| StyleBlock
|
|
|
|
| Para
|
|
|
|
| Plain )
|
|
|
|
|
|
|
|
Para = NonindentSpace a:Inlines BlankLine+
|
|
|
|
{ $$ = a; $$.key = PARA }
|
|
|
|
|
|
|
|
Plain = a:Inlines
|
|
|
|
{ $$ = a; $$.key = PLAIN }
|
|
|
|
|
2011-02-21 01:53:09 +00:00
|
|
|
AtxInline = !Newline !(Sp? '#'* Sp Newline) Inline
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2010-12-13 17:14:10 +00:00
|
|
|
AtxStart = &'#' < ( "######" | "#####" | "####" | "###" | "##" | "#" ) >
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkElem(H1 + (len(yytext) - 1)) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2011-02-21 01:55:06 +00:00
|
|
|
AtxHeading = s:AtxStart Sp? a:StartList ( AtxInline { a = cons($$, a) } )+ (Sp? '#'* Sp)? Newline
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(s.key, a)
|
2010-11-21 22:04:39 +00:00
|
|
|
s = nil }
|
|
|
|
|
|
|
|
SetextHeading = SetextHeading1 | SetextHeading2
|
|
|
|
|
2010-12-01 21:48:40 +00:00
|
|
|
SetextBottom1 = "===" '='* Newline
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2010-12-01 21:48:40 +00:00
|
|
|
SetextBottom2 = "---" '-'* Newline
|
|
|
|
|
|
|
|
SetextHeading1 = &(RawLine SetextBottom1)
|
2012-04-29 23:04:43 +00:00
|
|
|
a:StartList ( !Endline Inline { a = cons($$, a) } )+ Sp? Newline
|
2012-04-29 21:54:10 +00:00
|
|
|
SetextBottom1 { $$ = p.mkList(H1, a) }
|
2010-12-01 21:48:40 +00:00
|
|
|
|
|
|
|
SetextHeading2 = &(RawLine SetextBottom2)
|
2012-04-29 23:04:43 +00:00
|
|
|
a:StartList ( !Endline Inline { a = cons($$, a) } )+ Sp? Newline
|
2012-04-29 21:54:10 +00:00
|
|
|
SetextBottom2 { $$ = p.mkList(H2, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2012-04-29 23:06:43 +00:00
|
|
|
Heading = SetextHeading | AtxHeading
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
BlockQuote = a:BlockQuoteRaw
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkElem(BLOCKQUOTE)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.children = a
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockQuoteRaw = a:StartList
|
|
|
|
(( '>' ' '? Line { a = cons($$, a) } )
|
|
|
|
( !'>' !BlankLine Line { a = cons($$, a) } )*
|
2012-04-29 21:54:10 +00:00
|
|
|
( BlankLine { a = cons(p.mkString("\n"), a) } )*
|
2010-11-21 22:04:39 +00:00
|
|
|
)+
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkStringFromList(a, true)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.key = RAW
|
|
|
|
}
|
|
|
|
|
|
|
|
NonblankIndentedLine = !BlankLine IndentedLine
|
|
|
|
|
|
|
|
VerbatimChunk = a:StartList
|
2012-04-29 21:54:10 +00:00
|
|
|
( BlankLine { a = cons(p.mkString("\n"), a) } )*
|
2010-11-21 22:04:39 +00:00
|
|
|
( NonblankIndentedLine { a = cons($$, a) } )+
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkStringFromList(a, false) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Verbatim = a:StartList ( VerbatimChunk { a = cons($$, a) } )+
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkStringFromList(a, false)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.key = VERBATIM }
|
|
|
|
|
|
|
|
HorizontalRule = NonindentSpace
|
|
|
|
( '*' Sp '*' Sp '*' (Sp '*')*
|
|
|
|
| '-' Sp '-' Sp '-' (Sp '-')*
|
|
|
|
| '_' Sp '_' Sp '_' (Sp '_')*)
|
|
|
|
Sp Newline BlankLine+
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkElem(HRULE) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Bullet = !HorizontalRule NonindentSpace ('+' | '*' | '-') Spacechar+
|
|
|
|
|
|
|
|
BulletList = &Bullet (ListTight | ListLoose)
|
|
|
|
{ $$.key = BULLETLIST }
|
|
|
|
|
|
|
|
ListTight = a:StartList
|
2011-02-21 02:19:57 +00:00
|
|
|
( ListItemTight { a = cons($$, a) } )+
|
2010-12-13 18:36:35 +00:00
|
|
|
BlankLine* !(Bullet | Enumerator | DefMarker)
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(LIST, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
ListLoose = a:StartList
|
|
|
|
( b:ListItem BlankLine*
|
|
|
|
{
|
|
|
|
li := b.children
|
|
|
|
li.contents.str += "\n\n"
|
|
|
|
a = cons(b, a)
|
|
|
|
} )+
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(LIST, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2010-12-13 18:36:35 +00:00
|
|
|
ListItem = ( Bullet | Enumerator | DefMarker )
|
2010-11-21 22:04:39 +00:00
|
|
|
a:StartList
|
|
|
|
ListBlock { a = cons($$, a) }
|
|
|
|
( ListContinuationBlock { a = cons($$, a) } )*
|
|
|
|
{
|
2012-04-29 21:54:10 +00:00
|
|
|
raw := p.mkStringFromList(a, false)
|
2011-02-21 02:19:57 +00:00
|
|
|
raw.key = RAW
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkElem(LISTITEM)
|
2011-02-21 02:19:57 +00:00
|
|
|
$$.children = raw
|
|
|
|
}
|
|
|
|
|
|
|
|
ListItemTight =
|
|
|
|
( Bullet | Enumerator | DefMarker )
|
|
|
|
a:StartList
|
|
|
|
ListBlock { a = cons($$, a) }
|
|
|
|
( !BlankLine
|
|
|
|
ListContinuationBlock { a = cons($$, a) } )*
|
|
|
|
!ListContinuationBlock
|
|
|
|
{
|
2012-04-29 21:54:10 +00:00
|
|
|
raw := p.mkStringFromList(a, false)
|
2010-11-21 22:04:39 +00:00
|
|
|
raw.key = RAW
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkElem(LISTITEM)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.children = raw
|
|
|
|
}
|
|
|
|
|
|
|
|
ListBlock = a:StartList
|
2011-02-21 01:58:53 +00:00
|
|
|
!BlankLine Line { a = cons($$, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
( ListBlockLine { a = cons($$, a) } )*
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkStringFromList(a, false) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
ListContinuationBlock = a:StartList
|
|
|
|
( < BlankLine* >
|
|
|
|
{ if len(yytext) == 0 {
|
2012-04-29 21:54:10 +00:00
|
|
|
a = cons(p.mkString("\001"), a) // block separator
|
2010-11-21 22:04:39 +00:00
|
|
|
} else {
|
2012-04-29 21:54:10 +00:00
|
|
|
a = cons(p.mkString(yytext), a)
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
} )
|
|
|
|
( Indent ListBlock { a = cons($$, a) } )+
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkStringFromList(a, false) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Enumerator = NonindentSpace [0-9]+ '.' Spacechar+
|
|
|
|
|
|
|
|
OrderedList = &Enumerator (ListTight | ListLoose)
|
|
|
|
{ $$.key = ORDEREDLIST }
|
|
|
|
|
2011-02-21 01:58:53 +00:00
|
|
|
ListBlockLine = !BlankLine
|
|
|
|
!( (Indent? (Bullet | Enumerator)) | DefMarker )
|
2010-11-21 22:04:39 +00:00
|
|
|
!HorizontalRule
|
|
|
|
OptionallyIndentedLine
|
|
|
|
|
|
|
|
# Parsers for different kinds of block-level HTML content.
|
|
|
|
# This is repetitive due to constraints of PEG grammar.
|
|
|
|
|
|
|
|
HtmlBlockOpenAddress = '<' Spnl ("address" | "ADDRESS") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseAddress = '<' Spnl '/' ("address" | "ADDRESS") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockAddress = HtmlBlockOpenAddress (HtmlBlockAddress | !HtmlBlockCloseAddress .)* HtmlBlockCloseAddress
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenBlockquote = '<' Spnl ("blockquote" | "BLOCKQUOTE") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseBlockquote = '<' Spnl '/' ("blockquote" | "BLOCKQUOTE") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockBlockquote = HtmlBlockOpenBlockquote (HtmlBlockBlockquote | !HtmlBlockCloseBlockquote .)* HtmlBlockCloseBlockquote
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenCenter = '<' Spnl ("center" | "CENTER") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseCenter = '<' Spnl '/' ("center" | "CENTER") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockCenter = HtmlBlockOpenCenter (HtmlBlockCenter | !HtmlBlockCloseCenter .)* HtmlBlockCloseCenter
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenDir = '<' Spnl ("dir" | "DIR") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseDir = '<' Spnl '/' ("dir" | "DIR") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockDir = HtmlBlockOpenDir (HtmlBlockDir | !HtmlBlockCloseDir .)* HtmlBlockCloseDir
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenDiv = '<' Spnl ("div" | "DIV") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseDiv = '<' Spnl '/' ("div" | "DIV") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockDiv = HtmlBlockOpenDiv (HtmlBlockDiv | !HtmlBlockCloseDiv .)* HtmlBlockCloseDiv
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenDl = '<' Spnl ("dl" | "DL") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseDl = '<' Spnl '/' ("dl" | "DL") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockDl = HtmlBlockOpenDl (HtmlBlockDl | !HtmlBlockCloseDl .)* HtmlBlockCloseDl
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenFieldset = '<' Spnl ("fieldset" | "FIELDSET") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseFieldset = '<' Spnl '/' ("fieldset" | "FIELDSET") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockFieldset = HtmlBlockOpenFieldset (HtmlBlockFieldset | !HtmlBlockCloseFieldset .)* HtmlBlockCloseFieldset
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenForm = '<' Spnl ("form" | "FORM") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseForm = '<' Spnl '/' ("form" | "FORM") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockForm = HtmlBlockOpenForm (HtmlBlockForm | !HtmlBlockCloseForm .)* HtmlBlockCloseForm
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenH1 = '<' Spnl ("h1" | "H1") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseH1 = '<' Spnl '/' ("h1" | "H1") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockH1 = HtmlBlockOpenH1 (HtmlBlockH1 | !HtmlBlockCloseH1 .)* HtmlBlockCloseH1
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenH2 = '<' Spnl ("h2" | "H2") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseH2 = '<' Spnl '/' ("h2" | "H2") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockH2 = HtmlBlockOpenH2 (HtmlBlockH2 | !HtmlBlockCloseH2 .)* HtmlBlockCloseH2
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenH3 = '<' Spnl ("h3" | "H3") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseH3 = '<' Spnl '/' ("h3" | "H3") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockH3 = HtmlBlockOpenH3 (HtmlBlockH3 | !HtmlBlockCloseH3 .)* HtmlBlockCloseH3
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenH4 = '<' Spnl ("h4" | "H4") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseH4 = '<' Spnl '/' ("h4" | "H4") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockH4 = HtmlBlockOpenH4 (HtmlBlockH4 | !HtmlBlockCloseH4 .)* HtmlBlockCloseH4
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenH5 = '<' Spnl ("h5" | "H5") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseH5 = '<' Spnl '/' ("h5" | "H5") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockH5 = HtmlBlockOpenH5 (HtmlBlockH5 | !HtmlBlockCloseH5 .)* HtmlBlockCloseH5
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenH6 = '<' Spnl ("h6" | "H6") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseH6 = '<' Spnl '/' ("h6" | "H6") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockH6 = HtmlBlockOpenH6 (HtmlBlockH6 | !HtmlBlockCloseH6 .)* HtmlBlockCloseH6
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenMenu = '<' Spnl ("menu" | "MENU") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseMenu = '<' Spnl '/' ("menu" | "MENU") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockMenu = HtmlBlockOpenMenu (HtmlBlockMenu | !HtmlBlockCloseMenu .)* HtmlBlockCloseMenu
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenNoframes = '<' Spnl ("noframes" | "NOFRAMES") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseNoframes = '<' Spnl '/' ("noframes" | "NOFRAMES") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockNoframes = HtmlBlockOpenNoframes (HtmlBlockNoframes | !HtmlBlockCloseNoframes .)* HtmlBlockCloseNoframes
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenNoscript = '<' Spnl ("noscript" | "NOSCRIPT") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseNoscript = '<' Spnl '/' ("noscript" | "NOSCRIPT") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockNoscript = HtmlBlockOpenNoscript (HtmlBlockNoscript | !HtmlBlockCloseNoscript .)* HtmlBlockCloseNoscript
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenOl = '<' Spnl ("ol" | "OL") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseOl = '<' Spnl '/' ("ol" | "OL") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockOl = HtmlBlockOpenOl (HtmlBlockOl | !HtmlBlockCloseOl .)* HtmlBlockCloseOl
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenP = '<' Spnl ("p" | "P") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseP = '<' Spnl '/' ("p" | "P") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockP = HtmlBlockOpenP (HtmlBlockP | !HtmlBlockCloseP .)* HtmlBlockCloseP
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenPre = '<' Spnl ("pre" | "PRE") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockClosePre = '<' Spnl '/' ("pre" | "PRE") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockPre = HtmlBlockOpenPre (HtmlBlockPre | !HtmlBlockClosePre .)* HtmlBlockClosePre
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenTable = '<' Spnl ("table" | "TABLE") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseTable = '<' Spnl '/' ("table" | "TABLE") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockTable = HtmlBlockOpenTable (HtmlBlockTable | !HtmlBlockCloseTable .)* HtmlBlockCloseTable
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenUl = '<' Spnl ("ul" | "UL") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseUl = '<' Spnl '/' ("ul" | "UL") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockUl = HtmlBlockOpenUl (HtmlBlockUl | !HtmlBlockCloseUl .)* HtmlBlockCloseUl
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenDd = '<' Spnl ("dd" | "DD") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseDd = '<' Spnl '/' ("dd" | "DD") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockDd = HtmlBlockOpenDd (HtmlBlockDd | !HtmlBlockCloseDd .)* HtmlBlockCloseDd
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenDt = '<' Spnl ("dt" | "DT") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseDt = '<' Spnl '/' ("dt" | "DT") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockDt = HtmlBlockOpenDt (HtmlBlockDt | !HtmlBlockCloseDt .)* HtmlBlockCloseDt
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenFrameset = '<' Spnl ("frameset" | "FRAMESET") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseFrameset = '<' Spnl '/' ("frameset" | "FRAMESET") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockFrameset = HtmlBlockOpenFrameset (HtmlBlockFrameset | !HtmlBlockCloseFrameset .)* HtmlBlockCloseFrameset
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenLi = '<' Spnl ("li" | "LI") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseLi = '<' Spnl '/' ("li" | "LI") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockLi = HtmlBlockOpenLi (HtmlBlockLi | !HtmlBlockCloseLi .)* HtmlBlockCloseLi
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenTbody = '<' Spnl ("tbody" | "TBODY") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseTbody = '<' Spnl '/' ("tbody" | "TBODY") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockTbody = HtmlBlockOpenTbody (HtmlBlockTbody | !HtmlBlockCloseTbody .)* HtmlBlockCloseTbody
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenTd = '<' Spnl ("td" | "TD") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseTd = '<' Spnl '/' ("td" | "TD") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockTd = HtmlBlockOpenTd (HtmlBlockTd | !HtmlBlockCloseTd .)* HtmlBlockCloseTd
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenTfoot = '<' Spnl ("tfoot" | "TFOOT") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseTfoot = '<' Spnl '/' ("tfoot" | "TFOOT") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockTfoot = HtmlBlockOpenTfoot (HtmlBlockTfoot | !HtmlBlockCloseTfoot .)* HtmlBlockCloseTfoot
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenTh = '<' Spnl ("th" | "TH") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseTh = '<' Spnl '/' ("th" | "TH") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockTh = HtmlBlockOpenTh (HtmlBlockTh | !HtmlBlockCloseTh .)* HtmlBlockCloseTh
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenThead = '<' Spnl ("thead" | "THEAD") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseThead = '<' Spnl '/' ("thead" | "THEAD") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockThead = HtmlBlockOpenThead (HtmlBlockThead | !HtmlBlockCloseThead .)* HtmlBlockCloseThead
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenTr = '<' Spnl ("tr" | "TR") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseTr = '<' Spnl '/' ("tr" | "TR") Spnl '>'
|
2011-02-21 02:16:05 +00:00
|
|
|
HtmlBlockTr = HtmlBlockOpenTr (HtmlBlockTr | !HtmlBlockCloseTr .)* HtmlBlockCloseTr
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
HtmlBlockOpenScript = '<' Spnl ("script" | "SCRIPT") Spnl HtmlAttribute* '>'
|
|
|
|
HtmlBlockCloseScript = '<' Spnl '/' ("script" | "SCRIPT") Spnl '>'
|
2012-04-30 00:14:03 +00:00
|
|
|
HtmlBlockScript = HtmlBlockOpenScript (!HtmlBlockCloseScript .)* HtmlBlockCloseScript
|
2011-02-21 02:16:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
HtmlBlockInTags = HtmlBlockAddress
|
|
|
|
| HtmlBlockBlockquote
|
|
|
|
| HtmlBlockCenter
|
|
|
|
| HtmlBlockDir
|
|
|
|
| HtmlBlockDiv
|
|
|
|
| HtmlBlockDl
|
|
|
|
| HtmlBlockFieldset
|
|
|
|
| HtmlBlockForm
|
|
|
|
| HtmlBlockH1
|
|
|
|
| HtmlBlockH2
|
|
|
|
| HtmlBlockH3
|
|
|
|
| HtmlBlockH4
|
|
|
|
| HtmlBlockH5
|
|
|
|
| HtmlBlockH6
|
|
|
|
| HtmlBlockMenu
|
|
|
|
| HtmlBlockNoframes
|
|
|
|
| HtmlBlockNoscript
|
2011-02-21 08:11:51 +00:00
|
|
|
| HtmlBlockOl
|
2011-02-21 02:16:05 +00:00
|
|
|
| HtmlBlockP
|
|
|
|
| HtmlBlockPre
|
|
|
|
| HtmlBlockTable
|
|
|
|
| HtmlBlockUl
|
|
|
|
| HtmlBlockDd
|
|
|
|
| HtmlBlockDt
|
|
|
|
| HtmlBlockFrameset
|
|
|
|
| HtmlBlockLi
|
|
|
|
| HtmlBlockTbody
|
|
|
|
| HtmlBlockTd
|
|
|
|
| HtmlBlockTfoot
|
|
|
|
| HtmlBlockTh
|
|
|
|
| HtmlBlockThead
|
|
|
|
| HtmlBlockTr
|
|
|
|
| HtmlBlockScript
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2010-12-13 17:02:24 +00:00
|
|
|
HtmlBlock = &'<' < ( HtmlBlockInTags | HtmlComment | HtmlBlockSelfClosing ) >
|
2010-11-21 22:04:39 +00:00
|
|
|
BlankLine+
|
2010-11-24 18:56:25 +00:00
|
|
|
{ if p.extension.FilterHTML {
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkList(LIST, nil)
|
2010-11-21 22:04:39 +00:00
|
|
|
} else {
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkString(yytext)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.key = HTMLBLOCK
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HtmlBlockSelfClosing = '<' Spnl HtmlBlockType Spnl HtmlAttribute* '/' Spnl '>'
|
|
|
|
|
|
|
|
HtmlBlockType = "address" | "blockquote" | "center" | "dir" | "div" | "dl" | "fieldset" | "form" | "h1" | "h2" | "h3" |
|
|
|
|
"h4" | "h5" | "h6" | "hr" | "isindex" | "menu" | "noframes" | "noscript" | "ol" | "p" | "pre" | "table" |
|
|
|
|
"ul" | "dd" | "dt" | "frameset" | "li" | "tbody" | "td" | "tfoot" | "th" | "thead" | "tr" | "script" |
|
|
|
|
"ADDRESS" | "BLOCKQUOTE" | "CENTER" | "DIR" | "DIV" | "DL" | "FIELDSET" | "FORM" | "H1" | "H2" | "H3" |
|
|
|
|
"H4" | "H5" | "H6" | "HR" | "ISINDEX" | "MENU" | "NOFRAMES" | "NOSCRIPT" | "OL" | "P" | "PRE" | "TABLE" |
|
|
|
|
"UL" | "DD" | "DT" | "FRAMESET" | "LI" | "TBODY" | "TD" | "TFOOT" | "TH" | "THEAD" | "TR" | "SCRIPT"
|
|
|
|
|
|
|
|
StyleOpen = '<' Spnl ("style" | "STYLE") Spnl HtmlAttribute* '>'
|
|
|
|
StyleClose = '<' Spnl '/' ("style" | "STYLE") Spnl '>'
|
|
|
|
InStyleTags = StyleOpen (!StyleClose .)* StyleClose
|
|
|
|
StyleBlock = < InStyleTags >
|
|
|
|
BlankLine*
|
2010-11-24 18:56:25 +00:00
|
|
|
{ if p.extension.FilterStyles {
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkList(LIST, nil)
|
2010-11-21 22:04:39 +00:00
|
|
|
} else {
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkString(yytext)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.key = HTMLBLOCK
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Inlines = a:StartList ( !Endline Inline { a = cons($$, a) }
|
|
|
|
| c:Endline &Inline { a = cons(c, a) } )+ Endline?
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(LIST, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Inline = Str
|
|
|
|
| Endline
|
|
|
|
| UlOrStarLine
|
|
|
|
| Space
|
|
|
|
| Strong
|
|
|
|
| Emph
|
|
|
|
| Image
|
|
|
|
| Link
|
|
|
|
| NoteReference
|
|
|
|
| InlineNote
|
|
|
|
| Code
|
|
|
|
| RawHtml
|
|
|
|
| Entity
|
|
|
|
| EscapedChar
|
|
|
|
| Smart
|
|
|
|
| Symbol
|
|
|
|
|
|
|
|
Space = Spacechar+
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(" ")
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.key = SPACE }
|
|
|
|
|
2012-04-29 23:22:42 +00:00
|
|
|
Str = a:StartList < NormalChar+ > { a = cons(p.mkString(yytext), a) }
|
|
|
|
( StrChunk { a = cons($$, a) } )*
|
|
|
|
{ if a.next == nil { $$ = a; } else { $$ = p.mkList(LIST, a) } }
|
|
|
|
|
|
|
|
StrChunk = < (NormalChar | '_'+ &Alphanumeric)+ > { $$ = p.mkString(yytext) } |
|
|
|
|
AposChunk
|
|
|
|
|
|
|
|
AposChunk = &{ p.extension.Smart } '\'' &Alphanumeric
|
|
|
|
{ $$ = p.mkElem(APOSTROPHE) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
EscapedChar = '\\' !Newline < [-\\`|*_{}[\]()#+.!><] >
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(yytext) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Entity = ( HexEntity | DecEntity | CharEntity )
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(yytext); $$.key = HTML }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Endline = LineBreak | TerminalEndline | NormalEndline
|
|
|
|
|
|
|
|
NormalEndline = Sp Newline !BlankLine !'>' !AtxStart
|
|
|
|
!(Line ("===" '='* | "---" '-'*) Newline)
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString("\n")
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.key = SPACE }
|
|
|
|
|
|
|
|
TerminalEndline = Sp Newline Eof
|
|
|
|
{ $$ = nil }
|
|
|
|
|
|
|
|
LineBreak = " " NormalEndline
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkElem(LINEBREAK) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Symbol = < SpecialChar >
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(yytext) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
# This keeps the parser from getting bogged down on long strings of '*' or '_',
|
|
|
|
# or strings of '*' or '_' with space on each side:
|
2012-04-29 21:54:10 +00:00
|
|
|
UlOrStarLine = (UlLine | StarLine) { $$ = p.mkString(yytext) }
|
2010-11-21 22:04:39 +00:00
|
|
|
StarLine = < "****" '*'* > | < Spacechar '*'+ &Spacechar >
|
|
|
|
UlLine = < "____" '_'* > | < Spacechar '_'+ &Spacechar >
|
|
|
|
|
|
|
|
Emph = EmphStar | EmphUl
|
|
|
|
|
|
|
|
OneStarOpen = !StarLine '*' !Spacechar !Newline
|
2012-04-30 08:14:27 +00:00
|
|
|
OneStarClose = !Spacechar !Newline a:Inline '*' { $$ = a }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
EmphStar = OneStarOpen
|
|
|
|
a:StartList
|
|
|
|
( !OneStarClose Inline { a = cons($$, a) } )*
|
|
|
|
OneStarClose { a = cons($$, a) }
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(EMPH, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
OneUlOpen = !UlLine '_' !Spacechar !Newline
|
2012-04-30 08:16:52 +00:00
|
|
|
OneUlClose = !Spacechar !Newline a:Inline '_' !Alphanumeric { $$ = a }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
EmphUl = OneUlOpen
|
|
|
|
a:StartList
|
|
|
|
( !OneUlClose Inline { a = cons($$, a) } )*
|
|
|
|
OneUlClose { a = cons($$, a) }
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(EMPH, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Strong = StrongStar | StrongUl
|
|
|
|
|
|
|
|
TwoStarOpen = !StarLine "**" !Spacechar !Newline
|
|
|
|
TwoStarClose = !Spacechar !Newline a:Inline "**" { $$ = a }
|
|
|
|
|
|
|
|
StrongStar = TwoStarOpen
|
|
|
|
a:StartList
|
|
|
|
( !TwoStarClose Inline { a = cons($$, a) } )*
|
|
|
|
TwoStarClose { a = cons($$, a) }
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(STRONG, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
TwoUlOpen = !UlLine "__" !Spacechar !Newline
|
|
|
|
TwoUlClose = !Spacechar !Newline a:Inline "__" !Alphanumeric { $$ = a }
|
|
|
|
|
|
|
|
StrongUl = TwoUlOpen
|
|
|
|
a:StartList
|
|
|
|
( !TwoUlClose Inline { a = cons($$, a) } )*
|
|
|
|
TwoUlClose { a = cons($$, a) }
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(STRONG, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Image = '!' ( ExplicitLink | ReferenceLink )
|
2011-02-21 01:46:27 +00:00
|
|
|
{ if $$.key == LINK {
|
|
|
|
$$.key = IMAGE
|
|
|
|
} else {
|
|
|
|
result := $$
|
2012-04-29 21:54:10 +00:00
|
|
|
$$.children = cons(p.mkString("!"), result.children)
|
2011-02-21 01:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Link = ExplicitLink | ReferenceLink | AutoLink
|
|
|
|
|
|
|
|
ReferenceLink = ReferenceLinkDouble | ReferenceLinkSingle
|
|
|
|
|
|
|
|
ReferenceLinkDouble = a:Label < Spnl > !"[]" b:Label
|
|
|
|
{
|
|
|
|
if match, found := p.findReference(b.children); found {
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkLink(a.children, match.url, match.title);
|
2010-11-21 22:04:39 +00:00
|
|
|
a = nil
|
|
|
|
b = nil
|
|
|
|
} else {
|
2012-04-29 21:54:10 +00:00
|
|
|
result := p.mkElem(LIST)
|
|
|
|
result.children = cons(p.mkString("["), cons(a, cons(p.mkString("]"), cons(p.mkString(yytext),
|
|
|
|
cons(p.mkString("["), cons(b, p.mkString("]")))))))
|
2010-11-21 22:04:39 +00:00
|
|
|
$$ = result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReferenceLinkSingle = a:Label < (Spnl "[]")? >
|
|
|
|
{
|
|
|
|
if match, found := p.findReference(a.children); found {
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkLink(a.children, match.url, match.title)
|
2010-11-21 22:04:39 +00:00
|
|
|
a = nil
|
|
|
|
} else {
|
2012-04-29 21:54:10 +00:00
|
|
|
result := p.mkElem(LIST)
|
|
|
|
result.children = cons(p.mkString("["), cons(a, cons(p.mkString("]"), p.mkString(yytext))));
|
2010-11-21 22:04:39 +00:00
|
|
|
$$ = result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 21:09:53 +00:00
|
|
|
ExplicitLink = l:Label '(' Sp s:Source Spnl t:Title Sp ')'
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkLink(l.children, s.contents.str, t.contents.str)
|
2010-11-21 22:04:39 +00:00
|
|
|
s = nil
|
|
|
|
t = nil
|
|
|
|
l = nil }
|
|
|
|
|
|
|
|
Source = ( '<' < SourceContents > '>' | < SourceContents > )
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(yytext) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
SourceContents = ( ( !'(' !')' !'>' Nonspacechar )+ | '(' SourceContents ')')*
|
|
|
|
| ""
|
|
|
|
|
|
|
|
Title = ( TitleSingle | TitleDouble | < "" > )
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(yytext) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
TitleSingle = '\'' < ( !( '\'' Sp ( ')' | Newline ) ) . )* > '\''
|
|
|
|
|
|
|
|
TitleDouble = '"' < ( !( '"' Sp ( ')' | Newline ) ) . )* > '"'
|
|
|
|
|
|
|
|
AutoLink = AutoLinkUrl | AutoLinkEmail
|
|
|
|
|
|
|
|
AutoLinkUrl = '<' < [A-Za-z]+ "://" ( !Newline !'>' . )+ > '>'
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkLink(p.mkString(yytext), yytext, "") }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2012-04-30 08:10:32 +00:00
|
|
|
AutoLinkEmail = '<' ( "mailto:" )? < [-A-Za-z0-9+_./!%~$]+ '@' ( !Newline !'>' . )+ > '>'
|
2010-11-21 22:04:39 +00:00
|
|
|
{
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkLink(p.mkString(yytext), "mailto:"+yytext, "")
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 23:14:31 +00:00
|
|
|
Reference = NonindentSpace !"[]" l:Label ':' Spnl s:RefSrc t:RefTitle BlankLine+
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkLink(l.children, s.contents.str, t.contents.str)
|
2010-11-21 22:04:39 +00:00
|
|
|
s = nil
|
|
|
|
t = nil
|
|
|
|
l = nil
|
|
|
|
$$.key = REFERENCE }
|
|
|
|
|
2010-11-24 18:56:25 +00:00
|
|
|
Label = '[' ( !'^' &{ p.extension.Notes } | &. &{ !p.extension.Notes } )
|
2010-11-21 22:04:39 +00:00
|
|
|
a:StartList
|
|
|
|
( !']' Inline { a = cons($$, a) } )*
|
|
|
|
']'
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(LIST, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
RefSrc = < Nonspacechar+ >
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(yytext)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.key = HTML }
|
|
|
|
|
|
|
|
RefTitle = ( RefTitleSingle | RefTitleDouble | RefTitleParens | EmptyTitle )
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(yytext) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
EmptyTitle = < "" >
|
|
|
|
|
2012-04-29 23:14:31 +00:00
|
|
|
RefTitleSingle = Spnl '\'' < ( !( '\'' Sp Newline | Newline ) . )* > '\''
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2012-04-29 23:14:31 +00:00
|
|
|
RefTitleDouble = Spnl '"' < ( !('"' Sp Newline | Newline) . )* > '"'
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2012-04-29 23:14:31 +00:00
|
|
|
RefTitleParens = Spnl '(' < ( !(')' Sp Newline | Newline) . )* > ')'
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
References = a:StartList
|
|
|
|
( b:Reference { a = cons(b, a) } | SkipBlock )*
|
|
|
|
{ p.references = reverse(a) }
|
|
|
|
commit
|
|
|
|
|
|
|
|
Ticks1 = "`" !'`'
|
|
|
|
Ticks2 = "``" !'`'
|
|
|
|
Ticks3 = "```" !'`'
|
|
|
|
Ticks4 = "````" !'`'
|
|
|
|
Ticks5 = "`````" !'`'
|
|
|
|
|
|
|
|
Code = ( Ticks1 Sp < ( ( !'`' Nonspacechar )+ | !Ticks1 '`'+ | !( Sp Ticks1 ) ( Spacechar | Newline !BlankLine ) )+ > Sp Ticks1
|
|
|
|
| Ticks2 Sp < ( ( !'`' Nonspacechar )+ | !Ticks2 '`'+ | !( Sp Ticks2 ) ( Spacechar | Newline !BlankLine ) )+ > Sp Ticks2
|
|
|
|
| Ticks3 Sp < ( ( !'`' Nonspacechar )+ | !Ticks3 '`'+ | !( Sp Ticks3 ) ( Spacechar | Newline !BlankLine ) )+ > Sp Ticks3
|
|
|
|
| Ticks4 Sp < ( ( !'`' Nonspacechar )+ | !Ticks4 '`'+ | !( Sp Ticks4 ) ( Spacechar | Newline !BlankLine ) )+ > Sp Ticks4
|
|
|
|
| Ticks5 Sp < ( ( !'`' Nonspacechar )+ | !Ticks5 '`'+ | !( Sp Ticks5 ) ( Spacechar | Newline !BlankLine ) )+ > Sp Ticks5
|
|
|
|
)
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(yytext); $$.key = CODE }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2012-04-30 00:16:21 +00:00
|
|
|
RawHtml = < (HtmlComment | HtmlBlockScript | HtmlTag) >
|
2010-11-24 18:56:25 +00:00
|
|
|
{ if p.extension.FilterHTML {
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkList(LIST, nil)
|
2010-11-21 22:04:39 +00:00
|
|
|
} else {
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkString(yytext)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.key = HTML
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BlankLine = Sp Newline
|
|
|
|
|
|
|
|
Quoted = '"' (!'"' .)* '"' | '\'' (!'\'' .)* '\''
|
2011-02-21 01:37:19 +00:00
|
|
|
HtmlAttribute = (AlphanumericAscii | '-')+ Spnl ('=' Spnl (Quoted | (!'>' Nonspacechar)+))? Spnl
|
2010-11-21 22:04:39 +00:00
|
|
|
HtmlComment = "<!--" (!"-->" .)* "-->"
|
2011-02-21 01:37:19 +00:00
|
|
|
HtmlTag = '<' Spnl '/'? AlphanumericAscii+ Spnl HtmlAttribute* '/'? Spnl '>'
|
2010-11-21 22:04:39 +00:00
|
|
|
Eof = !.
|
|
|
|
Spacechar = ' ' | '\t'
|
|
|
|
Nonspacechar = !Spacechar !Newline .
|
|
|
|
Newline = '\n' | '\r' '\n'?
|
|
|
|
Sp = Spacechar*
|
|
|
|
Spnl = Sp (Newline Sp)?
|
2012-04-30 08:07:49 +00:00
|
|
|
SpecialChar = '*' | '_' | '`' | '&' | '[' | ']' | '(' | ')' | '<' | '!' | '#' | '\\' | '\'' | '"' | ExtendedSpecialChar
|
2010-11-21 22:04:39 +00:00
|
|
|
NormalChar = !( SpecialChar | Spacechar | Newline ) .
|
2011-02-21 01:37:19 +00:00
|
|
|
NonAlphanumeric = [\000-\057\072-\100\133-\140\173-\177]
|
2011-02-21 01:48:43 +00:00
|
|
|
Alphanumeric = [0-9A-Za-z] | '\200' | '\201' | '\202' | '\203' | '\204' | '\205' | '\206' | '\207' | '\210' | '\211' | '\212' | '\213' | '\214' | '\215' | '\216' | '\217' | '\220' | '\221' | '\222' | '\223' | '\224' | '\225' | '\226' | '\227' | '\230' | '\231' | '\232' | '\233' | '\234' | '\235' | '\236' | '\237' | '\240' | '\241' | '\242' | '\243' | '\244' | '\245' | '\246' | '\247' | '\250' | '\251' | '\252' | '\253' | '\254' | '\255' | '\256' | '\257' | '\260' | '\261' | '\262' | '\263' | '\264' | '\265' | '\266' | '\267' | '\270' | '\271' | '\272' | '\273' | '\274' | '\275' | '\276' | '\277' | '\300' | '\301' | '\302' | '\303' | '\304' | '\305' | '\306' | '\307' | '\310' | '\311' | '\312' | '\313' | '\314' | '\315' | '\316' | '\317' | '\320' | '\321' | '\322' | '\323' | '\324' | '\325' | '\326' | '\327' | '\330' | '\331' | '\332' | '\333' | '\334' | '\335' | '\336' | '\337' | '\340' | '\341' | '\342' | '\343' | '\344' | '\345' | '\346' | '\347' | '\350' | '\351' | '\352' | '\353' | '\354' | '\355' | '\356' | '\357' | '\360' | '\361' | '\362' | '\363' | '\364' | '\365' | '\366' | '\367' | '\370' | '\371' | '\372' | '\373' | '\374' | '\375' | '\376' | '\377'
|
2011-02-21 01:37:19 +00:00
|
|
|
AlphanumericAscii = [A-Za-z0-9]
|
2010-11-21 22:04:39 +00:00
|
|
|
Digit = [0-9]
|
|
|
|
|
|
|
|
HexEntity = < '&' '#' [Xx] [0-9a-fA-F]+ ';' >
|
|
|
|
DecEntity = < '&' '#' [0-9]+ > ';' >
|
|
|
|
CharEntity = < '&' [A-Za-z0-9]+ ';' >
|
|
|
|
|
|
|
|
NonindentSpace = " " | " " | " " | ""
|
|
|
|
Indent = "\t" | " "
|
|
|
|
IndentedLine = Indent Line
|
|
|
|
OptionallyIndentedLine = Indent? Line
|
|
|
|
|
|
|
|
# StartList starts a list data structure that can be added to with cons:
|
|
|
|
StartList = &.
|
|
|
|
{ $$ = nil }
|
|
|
|
|
|
|
|
Line = RawLine
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(yytext) }
|
2010-11-21 22:04:39 +00:00
|
|
|
RawLine = ( < (!'\r' !'\n' .)* Newline > | < .+ > Eof )
|
|
|
|
|
2012-04-30 08:12:01 +00:00
|
|
|
SkipBlock = HtmlBlock
|
|
|
|
| ( !'#' !SetextBottom1 !SetextBottom2 !BlankLine RawLine )+ BlankLine*
|
2010-11-21 22:04:39 +00:00
|
|
|
| BlankLine+
|
2012-04-30 08:13:12 +00:00
|
|
|
| RawLine
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
# Syntax extensions
|
|
|
|
|
2010-11-24 18:56:25 +00:00
|
|
|
ExtendedSpecialChar = &{ p.extension.Smart } ('.' | '-' | '\'' | '"')
|
|
|
|
| &{ p.extension.Notes } ( '^' )
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2010-11-24 18:56:25 +00:00
|
|
|
Smart = &{ p.extension.Smart }
|
2010-11-21 22:04:39 +00:00
|
|
|
( Ellipsis | Dash | SingleQuoted | DoubleQuoted | Apostrophe )
|
|
|
|
|
|
|
|
Apostrophe = '\''
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkElem(APOSTROPHE) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Ellipsis = ("..." | ". . .")
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkElem(ELLIPSIS) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
Dash = EmDash | EnDash
|
|
|
|
|
|
|
|
EnDash = '-' &Digit
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkElem(ENDASH) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
EmDash = ("---" | "--")
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkElem(EMDASH) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2012-04-30 00:10:03 +00:00
|
|
|
SingleQuoteStart = '\'' !(Spacechar | Newline)
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2011-02-21 01:39:40 +00:00
|
|
|
SingleQuoteEnd = '\'' !Alphanumeric
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
SingleQuoted = SingleQuoteStart
|
|
|
|
a:StartList
|
|
|
|
( !SingleQuoteEnd b:Inline { a = cons(b, a) } )+
|
|
|
|
SingleQuoteEnd
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(SINGLEQUOTED, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
|
|
|
DoubleQuoteStart = '"'
|
|
|
|
|
|
|
|
DoubleQuoteEnd = '"'
|
|
|
|
|
|
|
|
DoubleQuoted = DoubleQuoteStart
|
|
|
|
a:StartList
|
|
|
|
( !DoubleQuoteEnd b:Inline { a = cons(b, a) } )+
|
|
|
|
DoubleQuoteEnd
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(DOUBLEQUOTED, a) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2010-11-24 18:56:25 +00:00
|
|
|
NoteReference = &{ p.extension.Notes }
|
2010-11-21 22:04:39 +00:00
|
|
|
ref:RawNoteReference
|
|
|
|
{
|
|
|
|
if match, ok := p.find_note(ref.contents.str); ok {
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkElem(NOTE)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.children = match.children
|
|
|
|
$$.contents.str = ""
|
|
|
|
} else {
|
2012-04-29 21:54:10 +00:00
|
|
|
$$ = p.mkString("[^"+ref.contents.str+"]")
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RawNoteReference = "[^" < ( !Newline !']' . )+ > ']'
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkString(yytext) }
|
2010-11-21 22:04:39 +00:00
|
|
|
|
2010-11-24 18:56:25 +00:00
|
|
|
Note = &{ p.extension.Notes }
|
2010-11-21 22:04:39 +00:00
|
|
|
NonindentSpace ref:RawNoteReference ':' Sp
|
|
|
|
a:StartList
|
|
|
|
( RawNoteBlock { a = cons($$, a) } )
|
|
|
|
( &Indent RawNoteBlock { a = cons($$, a) } )*
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(NOTE, a)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.contents.str = ref.contents.str
|
|
|
|
}
|
|
|
|
|
2010-11-24 18:56:25 +00:00
|
|
|
InlineNote = &{ p.extension.Notes }
|
2010-11-21 22:04:39 +00:00
|
|
|
"^["
|
|
|
|
a:StartList
|
|
|
|
( !']' Inline { a = cons($$, a) } )+
|
|
|
|
']'
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(NOTE, a)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.contents.str = "" }
|
|
|
|
|
|
|
|
Notes = a:StartList
|
|
|
|
( b:Note { a = cons(b, a) } | SkipBlock )*
|
|
|
|
{ p.notes = reverse(a) }
|
|
|
|
commit
|
|
|
|
|
|
|
|
RawNoteBlock = a:StartList
|
|
|
|
( !BlankLine OptionallyIndentedLine { a = cons($$, a) } )+
|
2012-04-29 21:54:10 +00:00
|
|
|
( < BlankLine* > { a = cons(p.mkString(yytext), a) } )
|
|
|
|
{ $$ = p.mkStringFromList(a, true)
|
2010-11-21 22:04:39 +00:00
|
|
|
$$.key = RAW
|
|
|
|
}
|
|
|
|
|
2010-12-13 18:36:35 +00:00
|
|
|
|
|
|
|
DefinitionList = &{ p.extension.Dlists }
|
|
|
|
a:StartList
|
|
|
|
( Definition { a = cons($$, a) } )+
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(DEFINITIONLIST, a) }
|
2010-12-13 18:36:35 +00:00
|
|
|
|
2012-04-23 22:53:54 +00:00
|
|
|
Definition = &( (NonindentSpace !Defmark Nonspacechar RawLine) BlankLine? Defmark)
|
2010-12-13 18:36:35 +00:00
|
|
|
a:StartList
|
|
|
|
( DListTitle { a = cons($$, a) } )+
|
|
|
|
( DefTight | DefLoose ) {
|
|
|
|
for e := $$.children; e != nil; e = e.next {
|
|
|
|
e.key = DEFDATA
|
|
|
|
}
|
|
|
|
a = cons($$, a)
|
|
|
|
}
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(LIST, a) }
|
2010-12-13 18:36:35 +00:00
|
|
|
|
|
|
|
DListTitle = NonindentSpace !Defmark &Nonspacechar
|
|
|
|
a:StartList
|
|
|
|
(!Endline Inline { a = cons($$, a) } )+
|
|
|
|
Sp Newline
|
2012-04-29 21:54:10 +00:00
|
|
|
{ $$ = p.mkList(LIST, a)
|
2010-12-13 18:36:35 +00:00
|
|
|
$$.key = DEFTITLE
|
|
|
|
}
|
|
|
|
|
|
|
|
DefTight = &Defmark ListTight
|
|
|
|
DefLoose = BlankLine &Defmark ListLoose
|
|
|
|
|
|
|
|
Defmark = NonindentSpace (':' | '~') Spacechar+
|
|
|
|
DefMarker = &{ p.extension.Dlists } Defmark
|
|
|
|
|
|
|
|
|
2010-11-21 22:04:39 +00:00
|
|
|
%%
|
|
|
|
|
|
|
|
/*
|
|
|
|
* List manipulation functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* cons - cons an element onto a list, returning pointer to new head
|
|
|
|
*/
|
|
|
|
func cons(new, list *element) *element {
|
|
|
|
new.next = list
|
|
|
|
return new
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reverse - reverse a list, returning pointer to new list
|
|
|
|
*/
|
|
|
|
func reverse(list *element) (new *element) {
|
|
|
|
for list != nil {
|
|
|
|
next := list.next
|
|
|
|
new = cons(list, new)
|
|
|
|
list = next
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Auxiliary functions for parsing actions.
|
|
|
|
* These make it easier to build up data structures (including lists)
|
|
|
|
* in the parsing actions.
|
|
|
|
*/
|
|
|
|
|
2012-04-29 21:54:10 +00:00
|
|
|
/* p.mkElem - generic constructor for element
|
2010-11-21 22:04:39 +00:00
|
|
|
*/
|
2012-04-29 21:54:10 +00:00
|
|
|
func (p *yyParser) mkElem(key int) *element {
|
|
|
|
r := p.state.heap.row
|
|
|
|
if len(r) == 0 {
|
|
|
|
r = p.state.heap.nextRow()
|
2010-12-13 16:49:24 +00:00
|
|
|
}
|
2012-04-29 21:54:10 +00:00
|
|
|
e := &r[0]
|
|
|
|
*e = element{}
|
|
|
|
p.state.heap.row = r[1:]
|
2010-12-13 16:49:24 +00:00
|
|
|
e.key = key
|
|
|
|
return e
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 21:54:10 +00:00
|
|
|
/* p.mkString - constructor for STR element
|
2010-11-21 22:04:39 +00:00
|
|
|
*/
|
2012-04-29 21:54:10 +00:00
|
|
|
func (p *yyParser) mkString(s string) (result *element) {
|
|
|
|
result = p.mkElem(STR)
|
2010-11-21 22:04:39 +00:00
|
|
|
result.contents.str = s
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-04-29 21:54:10 +00:00
|
|
|
/* p.mkStringFromList - makes STR element by concatenating a
|
2010-11-21 22:04:39 +00:00
|
|
|
* reversed list of strings, adding optional extra newline
|
|
|
|
*/
|
2012-04-29 21:54:10 +00:00
|
|
|
func (p *yyParser) mkStringFromList(list *element, extra_newline bool) (result *element) {
|
2012-04-21 21:06:04 +00:00
|
|
|
s := ""
|
|
|
|
for list = reverse(list); list != nil; list = list.next {
|
|
|
|
s += list.contents.str
|
|
|
|
}
|
|
|
|
|
2010-11-21 22:04:39 +00:00
|
|
|
if extra_newline {
|
|
|
|
s += "\n"
|
|
|
|
}
|
2012-04-29 21:54:10 +00:00
|
|
|
result = p.mkElem(STR)
|
2010-11-21 22:04:39 +00:00
|
|
|
result.contents.str = s
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-04-29 21:54:10 +00:00
|
|
|
/* p.mkList - makes new list with key 'key' and children the reverse of 'lst'.
|
2010-11-21 22:04:39 +00:00
|
|
|
* This is designed to be used with cons to build lists in a parser action.
|
|
|
|
* The reversing is necessary because cons adds to the head of a list.
|
|
|
|
*/
|
2012-04-29 21:54:10 +00:00
|
|
|
func (p *yyParser) mkList(key int, lst *element) (el *element) {
|
|
|
|
el = p.mkElem(key)
|
2012-04-21 20:51:26 +00:00
|
|
|
el.children = reverse(lst)
|
|
|
|
return
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 21:54:10 +00:00
|
|
|
/* p.mkLink - constructor for LINK element
|
2010-11-21 22:04:39 +00:00
|
|
|
*/
|
2012-04-29 21:54:10 +00:00
|
|
|
func (p *yyParser) mkLink(label *element, url, title string) (el *element) {
|
|
|
|
el = p.mkElem(LINK)
|
2012-04-21 20:51:26 +00:00
|
|
|
el.contents.link = &link{label: label, url: url, title: title}
|
|
|
|
return
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* match_inlines - returns true if inline lists match (case-insensitive...)
|
|
|
|
*/
|
|
|
|
func match_inlines(l1, l2 *element) bool {
|
|
|
|
for l1 != nil && l2 != nil {
|
|
|
|
if l1.key != l2.key {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
switch l1.key {
|
|
|
|
case SPACE, LINEBREAK, ELLIPSIS, EMDASH, ENDASH, APOSTROPHE:
|
|
|
|
break
|
|
|
|
case CODE, STR, HTML:
|
|
|
|
if strings.ToUpper(l1.contents.str) != strings.ToUpper(l2.contents.str) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
case EMPH, STRONG, LIST, SINGLEQUOTED, DOUBLEQUOTED:
|
|
|
|
if !match_inlines(l1.children, l2.children) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
case LINK, IMAGE:
|
2013-01-23 20:51:00 +00:00
|
|
|
return false /* No links or images within links */
|
2010-11-21 22:04:39 +00:00
|
|
|
default:
|
2011-02-18 11:00:25 +00:00
|
|
|
log.Fatalf("match_inlines encountered unknown key = %d\n", l1.key)
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
l1 = l1.next
|
|
|
|
l2 = l2.next
|
|
|
|
}
|
2013-01-23 20:51:00 +00:00
|
|
|
return l1 == nil && l2 == nil /* return true if both lists exhausted */
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find_reference - return true if link found in references matching label.
|
|
|
|
* 'link' is modified with the matching url and title.
|
|
|
|
*/
|
2012-04-28 20:57:55 +00:00
|
|
|
func (p *yyParser) findReference(label *element) (*link, bool) {
|
|
|
|
for cur := p.references; cur != nil; cur = cur.next {
|
2010-11-21 22:04:39 +00:00
|
|
|
l := cur.contents.link
|
|
|
|
if match_inlines(label, l.label) {
|
|
|
|
return l, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find_note - return true if note found in notes matching label.
|
|
|
|
* if found, 'result' is set to point to matched note.
|
|
|
|
*/
|
2012-04-28 20:57:55 +00:00
|
|
|
func (p *yyParser) find_note(label string) (*element, bool) {
|
|
|
|
for el := p.notes; el != nil; el = el.next {
|
2010-11-21 22:04:39 +00:00
|
|
|
if label == el.contents.str {
|
|
|
|
return el, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print tree of elements, for debugging only.
|
|
|
|
*/
|
2012-04-21 21:08:33 +00:00
|
|
|
func print_tree(w io.Writer, elt *element, indent int) {
|
2010-11-21 22:04:39 +00:00
|
|
|
var key string
|
|
|
|
|
|
|
|
for elt != nil {
|
|
|
|
for i := 0; i < indent; i++ {
|
2012-04-21 21:08:33 +00:00
|
|
|
fmt.Fprint(w, "\t")
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
key = keynames[elt.key]
|
|
|
|
if key == "" {
|
|
|
|
key = "?"
|
|
|
|
}
|
|
|
|
if elt.key == STR {
|
2012-04-21 21:08:33 +00:00
|
|
|
fmt.Fprintf(w, "%p:\t%s\t'%s'\n", elt, key, elt.contents.str)
|
2010-11-21 22:04:39 +00:00
|
|
|
} else {
|
2012-04-21 21:08:33 +00:00
|
|
|
fmt.Fprintf(w, "%p:\t%s %p\n", elt, key, elt.next)
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
if elt.children != nil {
|
2012-04-21 21:08:33 +00:00
|
|
|
print_tree(w, elt.children, indent+1)
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|
|
|
|
elt = elt.next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var keynames = [numVAL]string{
|
2013-01-23 20:51:00 +00:00
|
|
|
LIST: "LIST",
|
|
|
|
RAW: "RAW",
|
|
|
|
SPACE: "SPACE",
|
|
|
|
LINEBREAK: "LINEBREAK",
|
|
|
|
ELLIPSIS: "ELLIPSIS",
|
|
|
|
EMDASH: "EMDASH",
|
|
|
|
ENDASH: "ENDASH",
|
|
|
|
APOSTROPHE: "APOSTROPHE",
|
|
|
|
SINGLEQUOTED: "SINGLEQUOTED",
|
|
|
|
DOUBLEQUOTED: "DOUBLEQUOTED",
|
|
|
|
STR: "STR",
|
|
|
|
LINK: "LINK",
|
|
|
|
IMAGE: "IMAGE",
|
|
|
|
CODE: "CODE",
|
|
|
|
HTML: "HTML",
|
|
|
|
EMPH: "EMPH",
|
|
|
|
STRONG: "STRONG",
|
|
|
|
PLAIN: "PLAIN",
|
|
|
|
PARA: "PARA",
|
|
|
|
LISTITEM: "LISTITEM",
|
|
|
|
BULLETLIST: "BULLETLIST",
|
|
|
|
ORDEREDLIST: "ORDEREDLIST",
|
|
|
|
H1: "H1",
|
|
|
|
H2: "H2",
|
|
|
|
H3: "H3",
|
|
|
|
H4: "H4",
|
|
|
|
H5: "H5",
|
|
|
|
H6: "H6",
|
|
|
|
BLOCKQUOTE: "BLOCKQUOTE",
|
|
|
|
VERBATIM: "VERBATIM",
|
|
|
|
HTMLBLOCK: "HTMLBLOCK",
|
|
|
|
HRULE: "HRULE",
|
|
|
|
REFERENCE: "REFERENCE",
|
|
|
|
NOTE: "NOTE",
|
|
|
|
DEFINITIONLIST: "DEFINITIONLIST",
|
|
|
|
DEFTITLE: "DEFTITLE",
|
|
|
|
DEFDATA: "DEFDATA",
|
2010-11-21 22:04:39 +00:00
|
|
|
}
|