From 9c75cf4103d70a6006e6a098cd7ecf55a357cd8f Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Thu, 28 Feb 2019 23:31:10 +0200 Subject: [PATCH 1/8] Add citation parser for markdown --- src/WeaveMarkdown/markdown.jl | 63 +++++++++++++++++++++++++++++- test/documents/bibtex/testdocs.bib | 41 +++++++++++++++++++ test/markdown_test.jl | 17 ++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 test/documents/bibtex/testdocs.bib diff --git a/src/WeaveMarkdown/markdown.jl b/src/WeaveMarkdown/markdown.jl index 5a70fa83..c4b78768 100644 --- a/src/WeaveMarkdown/markdown.jl +++ b/src/WeaveMarkdown/markdown.jl @@ -2,11 +2,24 @@ module WeaveMarkdown using Markdown import Markdown: @trigger, @breaking, Code, MD, withstream, startswith, LaTeX +using BibTeX mutable struct Comment text::String end +mutable struct Citation + key::String + no::Int64 + bib::Dict +end + +Citation(key, no) = Citation(key, no, Dict()) + +mutable struct Citations + content::Array{Citation} +end + @breaking true -> function dollarmath(stream::IO, block::MD) withstream(stream) do @@ -61,8 +74,45 @@ function comment(stream::IO, md::MD) end end +global const CITATIONS = Dict{Symbol, Any}( + :no => 1, + :bibtex => Dict(), + :references => [] + ) + +@trigger '[' -> +function citation(stream::IO, md::MD) + withstream(stream) do + Markdown.startswith(stream, "[@") || return + text = Markdown.readuntil(stream, ']', match = '[') + text ≡ nothing && return + citations = strip.(split(text, ";")) + cites = Citation[] + for c in citations + c = replace(c, r"^@" => "") + #Check for matcthing bixtex key + if haskey(CITATIONS[:bibtex], c) + bib = CITATIONS[:bibtex][c] + # Check for repeated citations + if haskey(CITATIONS[:refnumbers], c) + no = CITATIONS[:refnumbers][c] + else + no = CITATIONS[:no] + CITATIONS[:refnumbers][c] = no + CITATIONS[:no] += 1 + end + push!(cites, Citation(c, no, bib)) + CITATIONS[:references][c] = bib + else + push!(cites, Citation(c, 0)) + end + end + return Citations(cites) + end +end + # Create own flavor and copy all the features from julia flavor -Markdown.@flavor weavemd [dollarmath, comment, topcomment] +Markdown.@flavor weavemd [dollarmath, comment, topcomment, citation] weavemd.breaking = [weavemd.breaking; Markdown.julia.breaking] weavemd.regular = [weavemd.regular; Markdown.julia.regular] for key in keys(Markdown.julia.inner) @@ -73,6 +123,17 @@ for key in keys(Markdown.julia.inner) end end +function parse_markdown(text, bibfile) + CITATIONS[:no] = 1 + header, refs = parse_bibtex(read(bibfile, String)) + CITATIONS[:bibtex] = refs + CITATIONS[:references] = Dict() + CITATIONS[:refnumbers] = Dict() + m = Markdown.parse(text, flavor = weavemd); + m.content +end + + include("html.jl") include("latex.jl") end diff --git a/test/documents/bibtex/testdocs.bib b/test/documents/bibtex/testdocs.bib new file mode 100644 index 00000000..096ee1db --- /dev/null +++ b/test/documents/bibtex/testdocs.bib @@ -0,0 +1,41 @@ + +@Article{LubiDunn15, + Title = {Computing in Operations Research Using Julia}, + Author = {Miles Lubin and Iain Dunning}, + Journal = {INFORMS Journal on Computing}, + Year = {2015}, + Number = {2}, + Pages = {238--248}, + Volume = {27}, + Optdoi = {10.1287/ijoc.2014.0623}, + Opturl = {http://dx.doi.org/10.1287/ijoc.2014.0623} +} + +@article{pastell_filtering_2018, + title = {Filtering methods to improve the accuracy of indoor positioning data for dairy cows}, + volume = {169}, + issn = {1537-5110}, + url = {http://www.sciencedirect.com/science/article/pii/S1537511017308711}, + doi = {10.1016/j.biosystemseng.2018.01.008}, + urldate = {2018-03-28}, + journal = {Biosystems Engineering}, + author = {Pastell, Matti and Frondelius, Lilli and Järvinen, Mikko and Backman, Juha}, + month = may, + year = {2018}, + keywords = {Indoor positioning, Dairy, Extended Kalman filter, Ultra-wide band}, + pages = {22--31} +} + +@article{Bezanson2017, + doi = {10.1137/141000671}, + url = {https://doi.org/10.1137/141000671}, + year = {2017}, + month = {jan}, + publisher = {Society for Industrial {\&} Applied Mathematics ({SIAM})}, + volume = {59}, + number = {1}, + pages = {65--98}, + author = {Jeff Bezanson and Alan Edelman and Stefan Karpinski and Viral B. Shah}, + title = {Julia: A Fresh Approach to Numerical Computing}, + journal = {{SIAM} Review} +} diff --git a/test/markdown_test.jl b/test/markdown_test.jl index 5a051125..d2391d10 100644 --- a/test/markdown_test.jl +++ b/test/markdown_test.jl @@ -100,3 +100,20 @@ Multiple lines @test WeaveMarkdown.html(md.content[2]) == "

\\[\nx = 2\n\\]

" @test WeaveMarkdown.html(md.content[4]) == "\n\n" + +## +using Revise +import Weave: WeaveMarkdown + +md = """ + +[@Bezanson2017] + +citing [@pastell_filtering_2018; @someref] + +cite [@Bezanson2017] again + +""" + +m = WeaveMarkdown.parse_markdown(md, "test/documents/bibtex/testdocs.bib"); +m From 11f95b38446b7016cb235695a307e57e139ee8e1 Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Thu, 28 Feb 2019 23:39:49 +0200 Subject: [PATCH 2/8] Add BibTex to Project.toml --- Manifest.toml | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++ Project.toml | 21 +++---- 2 files changed, 172 insertions(+), 10 deletions(-) create mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 00000000..dcbe3b59 --- /dev/null +++ b/Manifest.toml @@ -0,0 +1,161 @@ +# This file is machine-generated - editing it directly is not advised + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BibTeX]] +git-tree-sha1 = "f434dde47e2c755c7cf9472bd394d1c074d7f475" +repo-rev = "master" +repo-url = "https://github.com/mpastell/BibTeX.jl.git" +uuid = "0c132655-f423-5f6f-9a5a-d55cfa15b9d7" +version = "0.0.0" + +[[Codecs]] +deps = ["Test"] +git-tree-sha1 = "70885e5e038cba1c4c17a84ad6c40756e10a4fb5" +uuid = "19ecbf4d-ef7c-5e4b-b54a-0a0ff23c5aed" +version = "0.5.0" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "49269e311ffe11ac5b334681d212329002a9832a" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.5.1" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[DocStringExtensions]] +deps = ["LibGit2", "Markdown", "Pkg", "Test"] +git-tree-sha1 = "1df01539a1c952cef21f2d2d1c092c2bcf0177d7" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.6.0" + +[[Highlights]] +deps = ["DocStringExtensions", "InteractiveUtils", "REPL", "Test"] +git-tree-sha1 = "286ff83d696dd92748e603a3219618d9e407e872" +uuid = "eafb193a-b7ab-5a9e-9068-77385905fa72" +version = "0.3.1" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[IteratorInterfaceExtensions]] +deps = ["Test"] +git-tree-sha1 = "5484e5ede2a4137b9643f4d646e8e7b87b794415" +uuid = "82899510-4779-5014-852e-03e436cf321d" +version = "0.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.20.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[Mustache]] +deps = ["Printf", "Tables", "Test"] +git-tree-sha1 = "3cc9a0b673519c5c39186e636d747facb12bf075" +uuid = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" +version = "0.5.11" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[TableTraits]] +deps = ["IteratorInterfaceExtensions", "Test"] +git-tree-sha1 = "eba4b1d0a82bdd773307d652c6e5f8c82104c676" +uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" +version = "0.4.1" + +[[Tables]] +deps = ["IteratorInterfaceExtensions", "LinearAlgebra", "Requires", "TableTraits", "Test"] +git-tree-sha1 = "5aa45584645393c1717e0cc1f0362c2ea81470a9" +uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +version = "0.1.17" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[YAML]] +deps = ["Codecs", "Compat"] +git-tree-sha1 = "3bde77cee95cce0c0b9b18813d85e18e8ed4f415" +uuid = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" +version = "0.3.2" diff --git a/Project.toml b/Project.toml index f364c160..eff461c7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,30 +1,31 @@ name = "Weave" uuid = "44d3d7a6-8a23-5bf8-98c5-b353f8df5ec9" -version="0.7.2" +version = "0.7.2" [deps] -Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" -Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" -Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" -REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" +BibTeX = "0c132655-f423-5f6f-9a5a-d55cfa15b9d7" Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" -Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" -JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Highlights = "eafb193a-b7ab-5a9e-9068-77385905fa72" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" -YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" +Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" Requires = "ae029012-a4dd-5104-9daa-d747884805df" +Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" +YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" [compat] Highlights = ">=0.3.1" +Mustache = ">=0.4.1" Plots = ">=0.19.0" YAML = ">=0.3.0" -Mustache = ">=0.4.1" [extras] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["Test", "Plots"] From 935303d1750859d384104d807e602c14410bfbfc Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Fri, 1 Mar 2019 10:47:29 +0200 Subject: [PATCH 3/8] Start working on ctation rendering --- REQUIRE | 1 + templates/html_citations.tpl | 3 +++ test/markdown_test.jl | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 templates/html_citations.tpl diff --git a/REQUIRE b/REQUIRE index 1e4c8694..341e4ce5 100644 --- a/REQUIRE +++ b/REQUIRE @@ -5,3 +5,4 @@ Mustache YAML Compat 0.25.0 Requires +BibTeX diff --git a/templates/html_citations.tpl b/templates/html_citations.tpl new file mode 100644 index 00000000..778e531b --- /dev/null +++ b/templates/html_citations.tpl @@ -0,0 +1,3 @@ +{{#article}} +{{author}}. ({{year}}). {{title}}. {{journal}}. {{volume}}:{{{pages}}}. doi: {{{doi}}}. +{{/article}} diff --git a/test/markdown_test.jl b/test/markdown_test.jl index d2391d10..26de3e86 100644 --- a/test/markdown_test.jl +++ b/test/markdown_test.jl @@ -104,6 +104,7 @@ Multiple lines ## using Revise import Weave: WeaveMarkdown +import Mustache md = """ @@ -115,5 +116,18 @@ cite [@Bezanson2017] again """ -m = WeaveMarkdown.parse_markdown(md, "test/documents/bibtex/testdocs.bib"); +m = WeaveMarkdown.parse_markdown(md, joinpath(@__DIR__, "documents/bibtex/testdocs.bib")); m +# Render references +tpl = Mustache.template_from_file(joinpath(@__DIR__, "../templates/html_citations.tpl")) +ref = WeaveMarkdown.CITATIONS[:references]["Bezanson2017"] +ref[ref["type"]] = "true" +ref["author"] = replace(ref["author"], r"\sand\s"i => ", ") +for key in keys(ref) + ref[key] = replace(ref[key], r"\{|\}" => "") + ref[key] = replace(ref[key], "--" => "—") +end + +Mustache.render(tpl, ref) +r2 = Dict("author" => "Matti Pastell", "title" => "Some paper", "article" => "true") +Mustache.render(tpl, r2) From b6eb19011c1e4d996e19a5070f542d4af717d7c3 Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Fri, 1 Mar 2019 14:43:46 +0200 Subject: [PATCH 4/8] Add basic citation formatting for html --- src/Weave.jl | 4 ++++ src/WeaveMarkdown/html.jl | 18 ++++++++++++++---- src/WeaveMarkdown/markdown.jl | 8 +++++--- test/markdown_test.jl | 5 +++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Weave.jl b/src/Weave.jl index fe8cd92f..97a8598e 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -103,6 +103,10 @@ function weave(source ; doctype = :auto, css != nothing && (doc.css = css) template != nothing && (doc.template = template) + if haskey(doc.header, "bibliography") + WeaveMarkdown.init_parser(joinpath(dirname(source), doc.header["bibliography"])) + end + try doc = run(doc, doctype = doctype, mod = mod, diff --git a/src/WeaveMarkdown/html.jl b/src/WeaveMarkdown/html.jl index 470ff7f4..9e59308c 100644 --- a/src/WeaveMarkdown/html.jl +++ b/src/WeaveMarkdown/html.jl @@ -1,4 +1,3 @@ -#module Markdown2HTML # Markdown to HTML writer, Modified from Julia Base.Markdown html writer using Markdown: MD, Header, Code, Paragraph, BlockQuote, Footnote, Admonition, List, HorizontalRule, Bold, Italic, Image, Link, LineBreak, @@ -230,10 +229,21 @@ function htmlinline(io::IO, comment::Comment) write(io, "") end +function htmlinline(io::IO, citations::Citations) + withtag(io, :span, :class => "citation") do + cites = [] + for c in citations.content + if c.no == 0 + push!(cites, "?") + else + push!(cites, c.no) + end + end + write(io, string("[", join(cites, ","), "]")) + end +end + htmlinline(io::IO, x) = tohtml(io, x) # API - html(md) = sprint(html, md) - -#end diff --git a/src/WeaveMarkdown/markdown.jl b/src/WeaveMarkdown/markdown.jl index c4b78768..c10a1fb8 100644 --- a/src/WeaveMarkdown/markdown.jl +++ b/src/WeaveMarkdown/markdown.jl @@ -123,16 +123,18 @@ for key in keys(Markdown.julia.inner) end end -function parse_markdown(text, bibfile) +#Init dictionary for parsing citations +function init_parser(bibfile) CITATIONS[:no] = 1 header, refs = parse_bibtex(read(bibfile, String)) CITATIONS[:bibtex] = refs CITATIONS[:references] = Dict() CITATIONS[:refnumbers] = Dict() - m = Markdown.parse(text, flavor = weavemd); - m.content end +function parse(text) + Markdown.parse(text, flavor = weavemd); +end include("html.jl") include("latex.jl") diff --git a/test/markdown_test.jl b/test/markdown_test.jl index 26de3e86..0686ee6e 100644 --- a/test/markdown_test.jl +++ b/test/markdown_test.jl @@ -116,8 +116,9 @@ cite [@Bezanson2017] again """ -m = WeaveMarkdown.parse_markdown(md, joinpath(@__DIR__, "documents/bibtex/testdocs.bib")); -m +WeaveMarkdown.init_parser(joinpath(@__DIR__, "documents/bibtex/testdocs.bib")) +m = WeaveMarkdown.parse(md); +m.content # Render references tpl = Mustache.template_from_file(joinpath(@__DIR__, "../templates/html_citations.tpl")) ref = WeaveMarkdown.CITATIONS[:references]["Bezanson2017"] From a6c7f1abb3c22f1911aef87f9790a29d3f25c2ce Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Fri, 1 Mar 2019 16:59:49 +0200 Subject: [PATCH 5/8] Add simple list of references --- src/Weave.jl | 2 ++ src/WeaveMarkdown/bibliography.jl | 26 ++++++++++++++++++++++++++ src/WeaveMarkdown/markdown.jl | 21 +++++++++++++++------ src/format.jl | 7 +++++++ templates/julia_html.tpl | 1 + test/markdown_test.jl | 3 +++ 6 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 src/WeaveMarkdown/bibliography.jl diff --git a/src/Weave.jl b/src/Weave.jl index 97a8598e..4bc63d80 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -121,6 +121,8 @@ function weave(source ; doctype = :auto, write(io, formatted) end + WeaveMarkdown.reset_parser() + #Special for that need external programs if doc.doctype == "pandoc2html" mdname = outname diff --git a/src/WeaveMarkdown/bibliography.jl b/src/WeaveMarkdown/bibliography.jl new file mode 100644 index 00000000..df21b56e --- /dev/null +++ b/src/WeaveMarkdown/bibliography.jl @@ -0,0 +1,26 @@ +import Mustache + +function list_references(m::MIME"text/html") + tpl = Mustache.template_from_file(joinpath(@__DIR__, "../../templates/html_citations.tpl")) + refs = Dict() + for key in keys(CITATIONS[:refnumbers]) + refs[CITATIONS[:refnumbers][key]] = key + end + io = IOBuffer() + write(io, "

References

") + write(io, "
    ") + for i in 1:length(refs) + ref = CITATIONS[:references][refs[i]] + ref[ref["type"]] = "true" + ref["author"] = replace(ref["author"], r"\sand\s"i => ", ") + for key in keys(ref) + ref[key] = replace(ref[key], r"\{|\}" => "") + ref[key] = replace(ref[key], "--" => "–") + end + write(io, "
  1. ") + write(io, Mustache.render(tpl, ref)) + write(io, "
  2. ") + end + write(io, "
") + return String(take!(io)) +end diff --git a/src/WeaveMarkdown/markdown.jl b/src/WeaveMarkdown/markdown.jl index c10a1fb8..7cbd8ccd 100644 --- a/src/WeaveMarkdown/markdown.jl +++ b/src/WeaveMarkdown/markdown.jl @@ -74,12 +74,6 @@ function comment(stream::IO, md::MD) end end -global const CITATIONS = Dict{Symbol, Any}( - :no => 1, - :bibtex => Dict(), - :references => [] - ) - @trigger '[' -> function citation(stream::IO, md::MD) withstream(stream) do @@ -123,6 +117,13 @@ for key in keys(Markdown.julia.inner) end end +const CITATIONS = Dict{Symbol, Any}( + :no => 1, + :bibtex => Dict(), + :references => Dict(), + :refnumbers => Dict() + ) + #Init dictionary for parsing citations function init_parser(bibfile) CITATIONS[:no] = 1 @@ -132,10 +133,18 @@ function init_parser(bibfile) CITATIONS[:refnumbers] = Dict() end +function reset_parser() + CITATIONS[:no] = 1 + CITATIONS[:references] = Dict() + CITATIONS[:bibtex] = Dict() + CITATIONS[:refnumbers] = Dict() +end + function parse(text) Markdown.parse(text, flavor = weavemd); end include("html.jl") include("latex.jl") +include("bibliography.jl") end diff --git a/src/format.jl b/src/format.jl index c202635a..04ef06d7 100644 --- a/src/format.jl +++ b/src/format.jl @@ -77,9 +77,16 @@ function render_doc(formatted, doc::WeaveDoc, format::JMarkdown2HTML) template = Mustache.template_from_file(doc.template) end + if isempty(WeaveMarkdown.CITATIONS[:references]) + references = "" + else + references = WeaveMarkdown.list_references(MIME"text/html"()) + end + return Mustache.render(template; themecss = theme_css, highlightcss = css, body = formatted, header_script = doc.header_script, source = wsource, wtime = wtime, wversion = wversion, + references = references, [Pair(Symbol(k), v) for (k,v) in doc.header]...) end diff --git a/templates/julia_html.tpl b/templates/julia_html.tpl index f665d58d..5e87fef5 100644 --- a/templates/julia_html.tpl +++ b/templates/julia_html.tpl @@ -38,6 +38,7 @@ {{{ :body }}} + {{{ :references }}}