Merge branch 'master' into table-caption
This commit is contained in:
commit
b16b8aba0b
|
@ -857,9 +857,8 @@ func (r *Renderer) citation(w io.Writer, node *ast.Citation) {
|
|||
attr[0] = `class="suppressed"`
|
||||
}
|
||||
r.outTag(w, "<cite", attr)
|
||||
r.outs(w, "[")
|
||||
r.out(w, c)
|
||||
r.outs(w, "]</cite>")
|
||||
r.outs(w, fmt.Sprintf(`<a href="#`+"%s"+`"></a>`, c))
|
||||
r.outs(w, "</cite>")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -908,7 +907,7 @@ func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Wal
|
|||
case *ast.Link:
|
||||
r.link(w, node, entering)
|
||||
case *ast.CrossReference:
|
||||
link := &ast.Link{Destination: node.Destination}
|
||||
link := &ast.Link{Destination: append([]byte("#"), node.Destination...)}
|
||||
r.link(w, link, entering)
|
||||
case *ast.Citation:
|
||||
r.citation(w, node)
|
||||
|
|
|
@ -927,7 +927,7 @@ func (p *Parser) fencedCodeBlock(data []byte, doRender bool) int {
|
|||
}
|
||||
|
||||
// Check for caption and if found make it a figure.
|
||||
if captionContent, consumed := p.caption(data[beg:]); consumed > 0 {
|
||||
if captionContent, consumed := p.caption(data[beg:], []byte("Figure: ")); consumed > 0 {
|
||||
figure := &ast.CaptionFigure{}
|
||||
caption := &ast.Caption{}
|
||||
p.Inline(caption, captionContent)
|
||||
|
@ -1260,7 +1260,7 @@ func (p *Parser) quote(data []byte) int {
|
|||
return end
|
||||
}
|
||||
|
||||
if captionContent, consumed := p.caption(data[end:]); consumed > 0 {
|
||||
if captionContent, consumed := p.caption(data[end:], []byte("Quote: ")); consumed > 0 {
|
||||
figure := &ast.CaptionFigure{}
|
||||
caption := &ast.Caption{}
|
||||
p.Inline(caption, captionContent)
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"bytes"
|
||||
)
|
||||
|
||||
func (p *Parser) caption(data []byte) ([]byte, int) {
|
||||
if !bytes.HasPrefix(data, []byte("Caption: ")) {
|
||||
func (p *Parser) caption(data, caption []byte) ([]byte, int) {
|
||||
if !bytes.HasPrefix(data, caption) {
|
||||
return nil, 0
|
||||
}
|
||||
j := len("Caption: ")
|
||||
j := len(caption)
|
||||
data = data[j:]
|
||||
end := p.linesUntilEmpty(data)
|
||||
|
||||
|
|
|
@ -10,13 +10,14 @@ import (
|
|||
// an address to select which lines to include. It is treated as an opaque string and just given
|
||||
// to readInclude.
|
||||
func (p *Parser) isInclude(data []byte) (filename string, address []byte, consumed int) {
|
||||
i := 0
|
||||
if len(data) < 3 {
|
||||
i := skipCharN(data, 0, ' ', 3) // start with up to 3 spaces
|
||||
if len(data[i:]) < 3 {
|
||||
return "", nil, 0
|
||||
}
|
||||
if data[i] != '{' || data[i+1] != '{' {
|
||||
return "", nil, 0
|
||||
}
|
||||
start := i + 2
|
||||
|
||||
// find the end delimiter
|
||||
i = skipUntilChar(data, i, '}')
|
||||
|
@ -28,7 +29,7 @@ func (p *Parser) isInclude(data []byte) (filename string, address []byte, consum
|
|||
if data[i] != '}' {
|
||||
return "", nil, 0
|
||||
}
|
||||
filename = string(data[2:end])
|
||||
filename = string(data[start:end])
|
||||
|
||||
if i+1 < len(data) && data[i+1] == '[' { // potential address specification
|
||||
start := i + 2
|
||||
|
@ -54,17 +55,20 @@ func (p *Parser) readInclude(from, file string, address []byte) []byte {
|
|||
|
||||
// isCodeInclude parses <{{...}} which is similar to isInclude the returned bytes are, however wrapped in a code block.
|
||||
func (p *Parser) isCodeInclude(data []byte) (filename string, address []byte, consumed int) {
|
||||
if len(data) < 3 {
|
||||
i := skipCharN(data, 0, ' ', 3) // start with up to 3 spaces
|
||||
if len(data[i:]) < 3 {
|
||||
return "", nil, 0
|
||||
}
|
||||
if data[0] != '<' {
|
||||
if data[i] != '<' {
|
||||
return "", nil, 0
|
||||
}
|
||||
filename, address, consumed = p.isInclude(data[1:])
|
||||
start := i
|
||||
|
||||
filename, address, consumed = p.isInclude(data[i+1:])
|
||||
if consumed == 0 {
|
||||
return "", nil, 0
|
||||
}
|
||||
return filename, address, consumed + 1
|
||||
return filename, address, start + consumed + 1
|
||||
}
|
||||
|
||||
// readCodeInclude acts like include except the returned bytes are wrapped in a fenced code block.
|
||||
|
|
|
@ -29,6 +29,10 @@ func TestIsInclude(t *testing.T) {
|
|||
[]byte("{{foo}}a]"),
|
||||
"foo", "", 7,
|
||||
},
|
||||
{
|
||||
[]byte(" {{foo}}"),
|
||||
"foo", "", 10,
|
||||
},
|
||||
// fails
|
||||
{
|
||||
[]byte("{foo}}"),
|
||||
|
@ -74,6 +78,10 @@ func TestIsCodeInclude(t *testing.T) {
|
|||
[]byte("<{{foo}} "),
|
||||
"foo", "", 8,
|
||||
},
|
||||
{
|
||||
[]byte(" <{{foo}} "),
|
||||
"foo", "", 11,
|
||||
},
|
||||
}
|
||||
|
||||
p := New()
|
||||
|
|
|
@ -64,7 +64,7 @@ func maybeShortRefOrIndex(p *Parser, data []byte, offset int) (int, ast.Node) {
|
|||
|
||||
idx := &ast.Index{}
|
||||
|
||||
idx.ID = fmt.Sprintf("idx-%d", p.indexCnt)
|
||||
idx.ID = fmt.Sprintf("idxref:%d", p.indexCnt)
|
||||
p.indexCnt++
|
||||
|
||||
idx.Primary = data[start] == '!'
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
~~~ go
|
||||
println("hi")
|
||||
~~~
|
||||
Caption: This *is* a
|
||||
Figure: This *is* a
|
||||
caption.
|
||||
+++
|
||||
<h1>Test Code Captions</h1>
|
||||
|
@ -35,7 +35,7 @@ Caption: This *is* a
|
|||
# Test Quote Captions
|
||||
> To be, or not to be
|
||||
|
||||
Caption: Shakespeare.
|
||||
Quote: Shakespeare.
|
||||
+++
|
||||
<h1>Test Quote Captions</h1>
|
||||
<figure>
|
||||
|
@ -56,21 +56,21 @@ Caption: Shakespeare.
|
|||
+++
|
||||
<h1>Test Citations</h1>
|
||||
|
||||
<p><cite class="informative">[RFC1034]</cite></p>
|
||||
<p><cite class="informative"><a href="#RFC1034"></a></cite></p>
|
||||
+++
|
||||
# Test Multiple Citations
|
||||
[@RFC1034; @!RFC1035]
|
||||
+++
|
||||
<h1>Test Multiple Citations</h1>
|
||||
|
||||
<p><cite class="informative">[RFC1034]</cite><cite class="normative">[RFC1035]</cite></p>
|
||||
<p><cite class="informative"><a href="#RFC1034"></a></cite><cite class="normative"><a href="#RFC1035"></a></cite></p>
|
||||
+++
|
||||
# Test Multiple Citations with modifier
|
||||
[@-RFC1034] [@?RFC1035]
|
||||
+++
|
||||
<h1>Test Multiple Citations with modifier</h1>
|
||||
|
||||
<p><cite class="suppressed">[RFC1034]</cite> <cite class="informative">[RFC1035]</cite></p>
|
||||
<p><cite class="suppressed"><a href="#RFC1034"></a></cite> <cite class="informative"><a href="#RFC1035"></a></cite></p>
|
||||
+++
|
||||
{.myclass1 .myclass2}
|
||||
~~~
|
||||
|
@ -87,16 +87,16 @@ code
|
|||
+++
|
||||
<h1>Index</h1>
|
||||
|
||||
<p><span class="index" id="idx-0"></span>
|
||||
<span class="index" id="idx-1"></span>
|
||||
<span class="index" id="idx-2"></span></p>
|
||||
<p><span class="index" id="idxref:0"></span>
|
||||
<span class="index" id="idxref:1"></span>
|
||||
<span class="index" id="idxref:2"></span></p>
|
||||
+++
|
||||
# Cross ref
|
||||
Look at (#basics)
|
||||
+++
|
||||
<h1>Cross ref</h1>
|
||||
|
||||
<p>Look at <a href="basics"></a></p>
|
||||
+++
|
||||
<p>Look at <a href="#basics"></a></p>
|
||||
+++
|
||||
Name | Age
|
||||
--------|------
|
||||
|
@ -126,4 +126,4 @@ Caption: Look at this table!
|
|||
</tbody>
|
||||
</table>
|
||||
<figcaption>Look at this table!</figcaption>
|
||||
</figure>
|
||||
</figure>
|
Loading…
Reference in New Issue