diff --git a/.gitignore b/.gitignore index 484e498..0256d89 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.swp tags doc/tags +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..2b7dcdc --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,398 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "bstr" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" +dependencies = [ + "memchr", +] + +[[package]] +name = "cc" +version = "1.0.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404b1fe4f65288577753b17e3b36a04596ee784493ec249bf81c7f2d2acd751c" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "ctor" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf6b25ee9ac1995c54d7adb2eff8cfffb7260bc774fb63c601ec65467f43cd9d" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "ghost" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a36606a68532b5640dc86bb1f33c64b45c4682aad4c50f3937b317ea387f3d6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "indoc" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79255cf29f5711995ddf9ec261b4057b1deb34e66c90656c201e41376872c544" +dependencies = [ + "indoc-impl", + "proc-macro-hack", +] + +[[package]] +name = "indoc-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54554010aa3d17754e484005ea0022f1c93839aabc627c2c55f3d7b47206134c" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", + "unindent", +] + +[[package]] +name = "inventory" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d3f4b90287725c97b17478c60dda0c6324e7c84ee1ed72fb9179d0fdf13956" +dependencies = [ + "ctor", + "ghost", + "inventory-impl", +] + +[[package]] +name = "inventory-impl" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9092a4fefc9d503e9287ef137f03180a6e7d1b04c419563171ee14947c5e80ec" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" + +[[package]] +name = "lock_api" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "mlua" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cb547f46dffcb8ce35738c836449bf0152f24787cdd9f8bf02c77d05d243d40" +dependencies = [ + "bstr", + "cc", + "lazy_static", + "num-traits", + "pkg-config", +] + +[[package]] +name = "mlua_derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0629c3166020d1361d0131cdeeb4ac8609d005c6c6c05fcebaacf65ae0c9d552" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "num-traits" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" +dependencies = [ + "autocfg", +] + +[[package]] +name = "parking_lot" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" +dependencies = [ + "cfg-if", + "cloudabi", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "paste" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a229b1c58c692edcaa5b9b0948084f130f55d2dcc15b02fcc5340b2b4521476" +dependencies = [ + "paste-impl", + "proc-macro-hack", +] + +[[package]] +name = "paste-impl" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e0bf239e447e67ff6d16a8bb5e4d4bd2343acf5066061c0e8e06ac5ba8ca68c" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pkg-config" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" + +[[package]] +name = "proc-macro-hack" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63" + +[[package]] +name = "proc-macro2" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "pulldown-cmark" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e142c3b8f49d2200605ee6ba0b1d757310e9e7a72afe78c36ee2ef67300ee00" +dependencies = [ + "bitflags", + "getopts", + "memchr", + "unicase", +] + +[[package]] +name = "pyo3" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80348539d1fa3fde72728c3fe9d750ec92c39e89908a774eda074289578c8d33" +dependencies = [ + "indoc", + "inventory", + "libc", + "parking_lot", + "paste", + "pyo3cls", + "unindent", + "version_check", +] + +[[package]] +name = "pyo3-derive-backend" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4d5d2e35fa26a8556dfca96c964249062deaa940b7e82e7c214f1bc21d646d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pyo3cls" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4628c487dbc084c17d4762bc0b531f373ca315997457708d6c9fabcc5c9928" +dependencies = [ + "pyo3-derive-backend", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42934bc9c8ab0d3b273a16d8551c8f0fcff46be73276ca083ec2414c15c4ba5e" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.1.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "smallvec" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" + +[[package]] +name = "syn" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4696caa4048ac7ce2bcd2e484b3cef88c1004e41b8e945a277e2c25dc0b72060" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" + +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" + +[[package]] +name = "unindent" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63f18aa3b0e35fed5a0048f029558b1518095ffe2a0a31fb87c93dece93a4993" + +[[package]] +name = "version_check" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" + +[[package]] +name = "vim-pandoc-syntax" +version = "0.0.0" +dependencies = [ + "mlua", + "mlua_derive", + "pulldown-cmark", + "pyo3", +] + +[[package]] +name = "winapi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e1c0b95 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,35 @@ +[package] +name = "vim-pandoc-syntax" +version = "0.0.0" +authors = [ + "Caleb Maclennan ", + "Felipe Morales " ] +edition = "2018" + +[lib] +name = 'vim_pandoc_syntax' +crate-type = ["cdylib"] + +[features] +default = ["python"] +python = ["pyo3"] +lua = ["mlua", "mlua_derive"] + +[dependencies.pulldown-cmark] +version = "0.7.1" +features = ["simd"] + +[dependencies.mlua] +optional = true +version = "0.3.2" +default-features = false +features = [ "luajit" ] + +[dependencies.mlua_derive] +optional = true +version = "0.3.0" + +[dependencies.pyo3] +optional = true +version = "0.10.1" +features = ["extension-module"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8759b2d --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +.ONESHELL: + +.PHONY: all +all: lua_lib python_lib links + +.PHONY: lua_lib +lua_lib: + export LUA_INC=/usr/include/luajit-2.0/ + export LUA_LIB=/usr/lib LUA_LIB_NAME=luajit-5.1 + export LUA_LINK=dynamic + cargo build --no-default-features --features lua --target-dir target-lua + +.PHONY: python_lib +python_lib: + cargo build --no-default-features --features python --target-dir target-python + +.PHONY: links + +links: lua/libvim_pandoc_syntax.so python3/libvim_pandoc_syntax.so + +lua/libvim_pandoc_syntax.so: lua_lib + mkdir -p $(@D) + ln -sf ../target-lua/debug/libvim_pandoc_syntax.so $@ + +python3/libvim_pandoc_syntax.so: python_lib + mkdir -p $(@D) + ln -sf ../target-python/debug/libvim_pandoc_syntax.so $@ diff --git a/lua/syntax_commonmark/init.lua b/lua/syntax_commonmark/init.lua new file mode 100644 index 0000000..2bce416 --- /dev/null +++ b/lua/syntax_commonmark/init.lua @@ -0,0 +1,75 @@ +package.loaded["rust"] = nil -- Force module reload during dev +local rust = require("libvim_pandoc_syntax") + +local rustymarks = vim.api.nvim_create_namespace("rustymarks") + +-- The Lua API is verbose and repetative +local call_function = vim.api.nvim_call_function +local buf_add_highlight = vim.api.nvim_buf_add_highlight +local buf_attach = vim.api.nvim_buf_attach +local buf_get_lines = vim.api.nvim_buf_get_lines +local buf_clear_namespace = vim.api.nvim_buf_clear_namespace + +local _attachments = {} + +function dump(...) + if select("#", ...) == 1 then + vim.api.nvim_out_write(vim.inspect((...))) + else + vim.api.nvim_out_write(vim.inspect {...}) + end + vim.api.nvim_out_write("\n") +end + +local function byte2pos (buffer, byte) + local line = call_function("byte2line", { byte }) + -- local col = byte - vim.api.nvim_buf_get_offset(buffer, line) + local col = byte - call_function("line2byte", { line }) + return line, col +end + +local function get_contents (buffer) + local lines = buf_get_lines(buffer, 0, -1, true) + for i = 1, #lines do lines[i] = lines[i] .. "\n" end + return table.concat(lines) +end + +function highlight (buffer) + local contents = get_contents(buffer) + local events = rust.get_offsets(contents) + for i, event in ipairs(events) do + local sline, scol = byte2pos(buffer, event.first) + local eline, ecol = byte2pos(buffer, event.last) + if sline < eline then + buf_add_highlight(buffer, rustymarks, event.group, sline - 1, scol, -1) + sline = sline + 1 + while sline < eline do + buf_add_highlight(buffer, rustymarks, event.group, sline - 1, 0, -1) + sline = sline + 1 + end + buf_add_highlight(buffer, rustymarks, event.group, sline - 1, 0, ecol) + else + buf_add_highlight(buffer, rustymarks, event.group, sline - 1, scol, ecol) + end + end +end + +local function attach (buffer) + if _attachments[buffer] then return end + _attachments[buffer] = true + highlight(buffer) + buf_attach(buffer, false, { + on_lines = function (event_type, buffer, changed_tick, firstline, lastline, new_lastline) + if not _attachments[buffer] then return end + buf_clear_namespace(buffer, rustymarks, 0, -1) + highlight(buffer) + end, + on_detach = function () + _attachments[buffer] = nil + end + }) +end + +return { + attach = attach, +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..329d195 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,88 @@ +#[cfg(feature = "lua")] +pub mod lua; + +#[cfg(feature = "python")] +pub mod python; + +use pulldown_cmark::{html, CodeBlockKind, Event, Options, Parser, Tag}; +use std::{error, result}; + +type Result = result::Result>; + +fn to_html(buffer: String) -> Result { + let options = Options::all(); + let parser = Parser::new_ext(buffer.as_str(), options); + let mut html_output = String::new(); + html::push_html(&mut html_output, parser); + Ok(html_output) +} + +#[derive(Debug)] +struct MdTag { + group: String, + first: usize, + last: usize, + lang: Option, +} + +type Events = Vec; + +fn get_offsets(buffer: String) -> Result { + let options = Options::all(); + let parser = Parser::new_ext(buffer.as_str(), options); + let mut events = Events::new(); + for (event, range) in parser.into_offset_iter() { + let first = range.start + 1; + let last = range.end + 1; + let mut lang = None; + let group = match event { + Event::Start(tag) => Some(match tag { + Tag::Heading(level) => format!("cmarkHeading{}", level), + Tag::CodeBlock(kind) => match kind { + CodeBlockKind::Indented => String::from("cmarkCodeBlockIndented"), + CodeBlockKind::Fenced(attrs) => { + lang = Some(attrs.to_string()); + String::from("cmarkCodeBlockFenced") + } + }, + Tag::List(_) => String::from("cmarkList"), + Tag::FootnoteDefinition(_) => String::from("cmarkFootnoteDefinition"), + Tag::Table(_) => String::from("cmarkTable"), + Tag::Link { .. } => String::from("cmarkLink"), + Tag::Image { .. } => String::from("cmarkImage"), + _ => format!("cmark{:?}", tag), + }), + Event::End { .. } => None, + Event::Text { .. } => Some(String::from("cmarkText")), + Event::Code { .. } => Some(String::from("cmarkCode")), + Event::Html { .. } => Some(String::from("cmarkHtml")), + Event::FootnoteReference { .. } => Some(String::from("cmarkFootnoteReference")), + Event::SoftBreak => None, + // Event::HardBreak => Some(String::from("cmarkHardBreak")), + Event::Rule => Some(String::from("cmarkRule")), + Event::TaskListMarker { .. } => Some(String::from("cmarkTaskListMarker")), + _other => Some(format!("cmark{:?}", _other)), + }; + if let Some(group) = group { + events.push(MdTag { + group, + first, + last, + lang, + }); + } + } + Ok(events) +} + +#[cfg(test)] +mod tests { + use crate::*; + use mlua::Lua; + + #[test] + fn can_render_html() { + let ret = render_html(&Lua::new(), String::from("# thing")).unwrap(); + assert_eq!(ret, "

thing

\n"); + } +} diff --git a/src/lua.rs b/src/lua.rs new file mode 100644 index 0000000..d2d2b94 --- /dev/null +++ b/src/lua.rs @@ -0,0 +1,27 @@ +use mlua::prelude::*; +use mlua_derive::*; + +fn to_html(_: &Lua, buffer: String) -> LuaResult { + Ok(super::to_html(buffer).unwrap()) +} + +fn get_offsets(lua: &Lua, buffer: String) -> LuaResult { + let table = lua.create_table().unwrap(); + let events = super::get_offsets(buffer).unwrap(); + for (i, event) in events.iter().enumerate() { + let info = lua.create_table().unwrap(); + info.set("group", event.group.as_str()).unwrap(); + info.set("first", event.first).unwrap(); + info.set("last", event.last).unwrap(); + table.set(i + 1, info).unwrap(); + } + Ok(table) +} + +#[lua_module] +fn libvim_pandoc_syntax(lua: &Lua) -> LuaResult { + let exports = lua.create_table()?; + exports.set("to_html", lua.create_function(to_html)?)?; + exports.set("get_offsets", lua.create_function(get_offsets)?)?; + Ok(exports) +} diff --git a/src/python.rs b/src/python.rs new file mode 100644 index 0000000..773dbd2 --- /dev/null +++ b/src/python.rs @@ -0,0 +1,23 @@ +use pyo3::prelude::*; +use pyo3::wrap_pyfunction; + +#[pyfunction] +fn to_html(_py: Python, buffer: String) -> PyResult { + Ok(super::to_html(buffer).unwrap()) +} + +#[pyfunction] +fn get_offsets(_py: Python, buffer: String) -> PyResult<()> { + let events = super::get_offsets(buffer).unwrap(); + for event in events.iter() { + eprintln!("DEBUG={:#?}", event); + } + Ok(()) +} + +#[pymodule] +fn libvim_pandoc_syntax(_py: Python, m: &PyModule) -> PyResult<()> { + m.add_wrapped(wrap_pyfunction!(to_html))?; + m.add_wrapped(wrap_pyfunction!(get_offsets))?; + Ok(()) +} diff --git a/syntax/pandoc.vim b/syntax/pandoc.vim index a393f29..c0418e1 100644 --- a/syntax/pandoc.vim +++ b/syntax/pandoc.vim @@ -1,6 +1,3 @@ -scriptencoding utf-8 -" vim: set fdm=marker foldlevel=0: -" " Vim syntax file " " Language: Pandoc (superset of Markdown) @@ -9,692 +6,20 @@ scriptencoding utf-8 " Contributor: David Sanson " Contributor: Jorge Israel Peña " OriginalAuthor: Jeremy Schultz -" Version: 5.0 - -" Configuration: {{{1 -" -" use conceal? {{{2 -if !exists('g:pandoc#syntax#conceal#use') - if v:version < 703 - let g:pandoc#syntax#conceal#use = 0 - else - let g:pandoc#syntax#conceal#use = 1 - endif -else - " exists, but we cannot use it, disable anyway - if v:version < 703 - let g:pandoc#syntax#conceal#use = 0 - endif -endif -"}}}2 - -" what groups not to use conceal in. works as a blacklist {{{2 -if !exists('g:pandoc#syntax#conceal#blacklist') - let g:pandoc#syntax#conceal#blacklist = [] -endif -" }}}2 - -" cchars used in conceal rules {{{2 -" utf-8 defaults (preferred) -if &encoding ==# 'utf-8' - let s:cchars = { - \'newline': '↵', - \'image': '▨', - \'super': 'ⁿ', - \'sub': 'ₙ', - \'strike': 'x̶', - \'atx': '§', - \'codelang': 'λ', - \'codeend': '—', - \'abbrev': '→', - \'footnote': '†', - \'definition': ' ', - \'li': '•', - \'html_c_s': '‹', - \'html_c_e': '›'} -else - " ascii defaults - let s:cchars = { - \'newline': ' ', - \'image': 'i', - \'super': '^', - \'sub': '_', - \'strike': '~', - \'atx': '#', - \'codelang': 'l', - \'codeend': '-', - \'abbrev': 'a', - \'footnote': 'f', - \'definition': ' ', - \'li': '*', - \'html_c_s': '+', - \'html_c_e': '+'} -endif -" }}}2 - -" if the user has a dictionary with replacements for the default cchars, use those {{{2 -if exists('g:pandoc#syntax#conceal#cchar_overrides') - let s:cchars = extend(s:cchars, g:pandoc#syntax#conceal#cchar_overrides) -endif -" }}}2 - -"should the urls in links be concealed? {{{2 -if !exists('g:pandoc#syntax#conceal#urls') - let g:pandoc#syntax#conceal#urls = 0 -endif -" should backslashes in escapes be concealed? {{{2 -if !exists('g:pandoc#syntax#conceal#backslash') - let g:pandoc#syntax#conceal#backslash = 0 -endif -" }}}2 - -" leave specified codeblocks as Normal (i.e. 'unhighlighted') {{{2 -if !exists('g:pandoc#syntax#codeblocks#ignore') - let g:pandoc#syntax#codeblocks#ignore = [] -endif -" }}}2 - -" use embedded highlighting for delimited codeblocks where a language is specifed. {{{2 -if !exists('g:pandoc#syntax#codeblocks#embeds#use') - let g:pandoc#syntax#codeblocks#embeds#use = 1 -endif -" }}}2 - -" for what languages and using what vim syntax files highlight those embeds. {{{2 -" defaults to None. -if !exists('g:pandoc#syntax#codeblocks#embeds#langs') - let g:pandoc#syntax#codeblocks#embeds#langs = [] -endif -" }}}2 - -" use italics ? {{{2 -if !exists('g:pandoc#syntax#style#emphases') - let g:pandoc#syntax#style#emphases = 1 -endif -" if 0, we don't conceal the emphasis marks, otherwise there wouldn't be a way -" to tell where the styles apply. -if g:pandoc#syntax#style#emphases == 0 - call add(g:pandoc#syntax#conceal#blacklist, 'block') -endif -" }}}2 - -" underline subscript, superscript and strikeout? {{{2 -if !exists('g:pandoc#syntax#style#underline_special') - let g:pandoc#syntax#style#underline_special = 1 -endif -" }}}2 - -" protect code blocks? {{{2 -if !exists('g:pandoc#syntax#protect#codeblocks') - let g:pandoc#syntax#protect#codeblocks = 1 -endif -" }}}2 - -" use color column? {{{2 -if !exists('g:pandoc#syntax#colorcolumn') - let g:pandoc#syntax#colorcolumn = 0 -endif -" }}}2 - -" highlight new lines? {{{2 -if !exists('g:pandoc#syntax#newlines') - let g:pandoc#syntax#newlines = 1 -endif -" }}} - -" detect roman-numeral list items? {{{2 -if !exists('g:pandoc#syntax#roman_lists') - let g:pandoc#syntax#roman_lists = 0 -endif -" }}}2 -" disable syntax highlighting for definition lists? (better performances) {{{2 -if !exists('g:pandoc#syntax#use_definition_lists') - let g:pandoc#syntax#use_definition_lists = 1 -endif -" }}}2 - -" }}}1 - -" Functions: {{{1 -" EnableEmbedsforCodeblocksWithLang {{{2 -function! EnableEmbedsforCodeblocksWithLang(entry) - " prevent embedded language syntaxes from changing 'foldmethod' - if has('folding') - let s:foldmethod = &l:foldmethod - endif - - try - let s:langname = matchstr(a:entry, '^[^=]*') - let s:langsyntaxfile = matchstr(a:entry, '[^=]*$') - unlet! b:current_syntax - exe 'syn include @'.toupper(s:langname).' syntax/'.s:langsyntaxfile.'.vim' - exe 'syn region pandocDelimitedCodeBlock_' . s:langname . ' start=/\(\_^\([ ]\{4,}\|\t\)\=\(`\{3,}`*\|\~\{3,}\~*\)\s*\%({[^.]*\.\)\=' . s:langname . '\>.*\n\)\@<=\_^/' . - \' end=/\_$\n\(\([ ]\{4,}\|\t\)\=\(`\{3,}`*\|\~\{3,}\~*\)\_$\n\_$\)\@=/ contained containedin=pandocDelimitedCodeBlock' . - \' contains=@' . toupper(s:langname) - exe 'syn region pandocDelimitedCodeBlockinBlockQuote_' . s:langname . ' start=/>\s\(`\{3,}`*\|\~\{3,}\~*\)\s*\%({[^.]*\.\)\=' . s:langname . '\>/' . - \ ' end=/\(`\{3,}`*\|\~\{3,}\~*\)/ contained containedin=pandocDelimitedCodeBlock' . - \' contains=@' . toupper(s:langname) . - \',pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd,pandodDelimitedCodeblockLang,pandocBlockQuoteinDelimitedCodeBlock' - catch /E484/ - echo "No syntax file found for '" . s:langsyntaxfile . "'" - endtry - - if exists('s:foldmethod') && s:foldmethod !=# &l:foldmethod - let &l:foldmethod = s:foldmethod - endif -endfunction -" }}}2 - -" DisableEmbedsforCodeblocksWithLang {{{2 -function! DisableEmbedsforCodeblocksWithLang(langname) - try - exe 'syn clear pandocDelimitedCodeBlock_'.a:langname - exe 'syn clear pandocDelimitedCodeBlockinBlockQuote_'.a:langname - catch /E28/ - echo "No existing highlight definitions found for '" . a:langname . "'" - endtry -endfunction -" }}}2 - -" WithConceal {{{2 -function! s:WithConceal(rule_group, rule, conceal_rule) - let l:rule_tail = '' - if g:pandoc#syntax#conceal#use != 0 - if index(g:pandoc#syntax#conceal#blacklist, a:rule_group) == -1 - let l:rule_tail = ' ' . a:conceal_rule - endif - endif - execute a:rule . l:rule_tail -endfunction -" }}}2 - -" }}}1 - -" Commands: {{{1 -command! -buffer -nargs=1 -complete=syntax PandocHighlight call EnableEmbedsforCodeblocksWithLang() -command! -buffer -nargs=1 -complete=syntax PandocUnhighlight call DisableEmbedsforCodeblocksWithLang() -" }}}1 - -" BASE: -syntax clear -syntax spell toplevel -" apply extra settings: {{{1 -if g:pandoc#syntax#colorcolumn == 1 - exe 'setlocal colorcolumn='.string(&textwidth+5) -elseif g:pandoc#syntax#colorcolumn == 2 - exe 'setlocal colorcolumn='.join(range(&textwidth+5, 2*&columns), ',') -endif -if g:pandoc#syntax#conceal#use != 0 - setlocal conceallevel=2 -endif -" }}}1 - -" Syntax Rules: {{{1 - -" Embeds: {{{2 - -" prevent embedded language syntaxes from changing 'foldmethod' -if has('folding') - let s:foldmethod = &l:foldmethod -endif - -" HTML: {{{3 -" Set embedded HTML highlighting -syn include @HTML syntax/html.vim -syn match pandocHTML /<\/\?\a.\{-}>/ contains=@HTML -" Support HTML multi line comments -syn region pandocHTMLComment start=// keepend contains=pandocHTMLCommentStart,pandocHTMLCommentEnd -call s:WithConceal('html_c_s', 'syn match pandocHTMLCommentStart // contained', 'conceal cchar='.s:cchars['html_c_e']) -" }}}3 - -" LaTeX: {{{3 -" Set embedded LaTex (pandoc extension) highlighting -" Unset current_syntax so the 2nd include will work -unlet b:current_syntax -syn include @LATEX syntax/tex.vim -syn region pandocLaTeXInlineMath start=/\v\\@.*\n\(.*\n\@1/ contained containedin=pandocEmphasis,pandocStrong,pandocPCite,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocUListItem,pandocNoFormatted -" }}}2 +scriptencoding utf-8 -" Code Blocks: {{{2 -if g:pandoc#syntax#protect#codeblocks == 1 - syn match pandocCodeblock /\([ ]\{4}\|\t\).*$/ +if exists('b:current_syntax') + finish endif -syn region pandocCodeBlockInsideIndent start=/\(\(\d\|\a\|*\).*\n\)\@/ contains=NONE -" }}}3 - -" }}}2 - -" Citations: {{{2 -" parenthetical citations -syn match pandocPCite "\^\@~/]*.\{-}\]" contains=pandocEmphasis,pandocStrong,pandocLatex,pandocCiteKey,@Spell,pandocAmpersandEscape display -" in-text citations with location -syn match pandocICite "@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\s\[.\{-1,}\]" contains=pandocCiteKey,@Spell display -" cite keys -syn match pandocCiteKey /\(-\=@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\)/ containedin=pandocPCite,pandocICite contains=@NoSpell display -syn match pandocCiteAnchor /[-@]/ contained containedin=pandocCiteKey display -syn match pandocCiteLocator /[\[\]]/ contained containedin=pandocPCite,pandocICite -" }}}2 - -" Text Styles: {{{2 - -" Emphasis: {{{3 -call s:WithConceal('block', 'syn region pandocEmphasis matchgroup=pandocOperator start=/\\\@1.*\n\|^\s*\n\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape,pandocReferenceLabel,pandocReferenceURL display -syn match pandocAtxHeaderMark /\(^#\{1,6}\|\\\@/ contained containedin=pandocGridTableHeader,pandocPipeTableHeader contains=@Spell -" }}}2 - -" Delimited Code Blocks: {{{2 -" this is here because we can override strikeouts and subscripts -syn region pandocDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\{4,}\|\t\)\=\~\{3,}\~*\)/ end=/^\z1\~*/ skipnl contains=pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd keepend -syn region pandocDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\{4,}\|\t\)\=`\{3,}`*\)/ end=/^\z1`*/ skipnl contains=pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd keepend -call s:WithConceal('codeblock_start', 'syn match pandocDelimitedCodeBlockStart /\(\_^\n\_^\(>\s\)\?\([ ]\{4,}\|\t\)\=\)\@<=\(\~\{3,}\~*\|`\{3,}`*\)/ contained containedin=pandocDelimitedCodeBlock nextgroup=pandocDelimitedCodeBlockLanguage', 'conceal cchar='.s:cchars['codelang']) -syn match pandocDelimitedCodeBlockLanguage /\(\s\?\)\@<=.\+\(\_$\)\@=/ contained -call s:WithConceal('codeblock_delim', 'syn match pandocDelimitedCodeBlockEnd /\(`\{3,}`*\|\~\{3,}\~*\)\(\_$\n\(>\s\)\?\_$\)\@=/ contained containedin=pandocDelimitedCodeBlock', 'conceal cchar='.s:cchars['codeend']) -syn match pandocBlockQuoteinDelimitedCodeBlock '^>' contained containedin=pandocDelimitedCodeBlock -syn match pandocCodePre /
.\{-}<\/pre>/ skipnl
-syn match pandocCodePre /.\{-}<\/code>/ skipnl
-
-" enable highlighting for embedded region in codeblocks if there exists a
-" g:pandoc#syntax#codeblocks#embeds#langs *list*.
-"
-" entries in this list are the language code interpreted by pandoc,
-" if this differs from the name of the vim syntax file, append =vimname
-" e.g. let g:pandoc#syntax#codeblocks#embeds#langs = ["haskell", "literatehaskell=lhaskell"]
-"
-if g:pandoc#syntax#codeblocks#embeds#use != 0
-    for l in g:pandoc#syntax#codeblocks#embeds#langs
-      call EnableEmbedsforCodeblocksWithLang(l)
-    endfor
-endif
-" }}}2
-
-" Abbreviations: {{{2
-syn region pandocAbbreviationDefinition start=/^\*\[.\{-}\]:\s*/ end='$' contains=pandocNoFormatted,@Spell,pandocAmpersandEscape
-call s:WithConceal('abbrev', 'syn match pandocAbbreviationSeparator /:/ contained containedin=pandocAbbreviationDefinition', 'conceal cchar='.s:cchars['abbrev'])
-syn match pandocAbbreviation /\*\[.\{-}\]/ contained containedin=pandocAbbreviationDefinition
-call s:WithConceal('abbrev', 'syn match pandocAbbreviationHead /\*\[/ contained containedin=pandocAbbreviation', 'conceal')
-call s:WithConceal('abbrev', 'syn match pandocAbbreviationTail /\]/ contained containedin=pandocAbbreviation', 'conceal')
-" }}}2
-
-" Footnotes: {{{2
-" we put these here not to interfere with superscripts.
-syn match pandocFootnoteID /\[\^[^\]]\+\]/ nextgroup=pandocFootnoteDef
-
-"   Inline footnotes
-syn region pandocFootnoteDef start=/\^\[/ skip=/\[.\{-}]/ end=/\]/ contains=pandocReferenceLabel,pandocReferenceURL,pandocLatex,pandocPCite,pandocCiteKey,pandocStrong,pandocEmphasis,pandocStrongEmphasis,pandocNoFormatted,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocEnDash,pandocEmDash,pandocEllipses,pandocBeginQuote,pandocEndQuote,@Spell,pandocAmpersandEscape skipnl keepend
-call s:WithConceal('footnote', 'syn match pandocFootnoteDefHead /\^\[/ contained containedin=pandocFootnoteDef', 'conceal cchar='.s:cchars['footnote'])
-call s:WithConceal('footnote', 'syn match pandocFootnoteDefTail /\]/ contained containedin=pandocFootnoteDef', 'conceal')
-
-" regular footnotes
-syn region pandocFootnoteBlock start=/\[\^.\{-}\]:\s*\n*/ end=/^\n^\s\@!/ contains=pandocReferenceLabel,pandocReferenceURL,pandocLatex,pandocPCite,pandocCiteKey,pandocStrong,pandocEmphasis,pandocNoFormatted,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocEnDash,pandocEmDash,pandocNewLine,pandocStrongEmphasis,pandocEllipses,pandocBeginQuote,pandocEndQuote,pandocLaTeXInlineMath,pandocEscapedDollar,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXRegion,pandocAmpersandEscape,@Spell skipnl
-syn match pandocFootnoteBlockSeparator /:/ contained containedin=pandocFootnoteBlock
-syn match pandocFootnoteID /\[\^.\{-}\]/ contained containedin=pandocFootnoteBlock
-call s:WithConceal('footnote', 'syn match pandocFootnoteIDHead /\[\^/ contained containedin=pandocFootnoteID', 'conceal cchar='.s:cchars['footnote'])
-call s:WithConceal('footnote', 'syn match pandocFootnoteIDTail /\]/ contained containedin=pandocFootnoteID', 'conceal')
-" }}}2
-
-" List Items: {{{2
-" Unordered lists
-syn match pandocUListItem /^>\=\s*[*+-]\s\+-\@!.*$/ nextgroup=pandocUListItem,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocDelimitedCodeBlock,pandocListItemContinuation contains=@Spell,pandocEmphasis,pandocStrong,pandocNoFormatted,pandocStrikeout,pandocSubscript,pandocSuperscript,pandocStrongEmphasis,pandocStrongEmphasis,pandocPCite,pandocICite,pandocCiteKey,pandocReferenceLabel,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocReferenceURL,pandocAutomaticLink,pandocFootnoteDef,pandocFootnoteBlock,pandocFootnoteID,pandocAmpersandEscape skipempty display
-call s:WithConceal('list', 'syn match pandocUListItemBullet /^>\=\s*\zs[*+-]/ contained containedin=pandocUListItem', 'conceal cchar='.s:cchars['li'])
-
-" Ordered lists
-syn match pandocListItem /^\s*(\?\(\d\+\|\l\|\#\|@\)[.)].*$/ nextgroup=pandocListItem,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocDelimitedCodeBlock,pandocListItemContinuation contains=@Spell,pandocEmphasis,pandocStrong,pandocNoFormatted,pandocStrikeout,pandocSubscript,pandocSuperscript,pandocStrongEmphasis,pandocStrongEmphasis,pandocPCite,pandocICite,pandocCiteKey,pandocReferenceLabel,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocAutomaticLink,pandocFootnoteDef,pandocFootnoteBlock,pandocFootnoteID,pandocAmpersandEscape skipempty display
-
-" support for roman numerals up to 'c'
-if g:pandoc#syntax#roman_lists != 0
-    syn match pandocListItem /^\s*(\?x\=l\=\(i\{,3}[vx]\=\)\{,3}c\{,3}[.)].*$/ nextgroup=pandocListItem,pandocMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocDelimitedCodeBlock,pandocListItemContinuation,pandocAutomaticLink skipempty display
-endif
-syn match pandocListItemBullet /^(\?.\{-}[.)]/ contained containedin=pandocListItem
-syn match pandocListItemBulletId /\(\d\+\|\l\|\#\|@.\{-}\|x\=l\=\(i\{,3}[vx]\=\)\{,3}c\{,3}\)/ contained containedin=pandocListItemBullet
-
-syn match pandocListItemContinuation /^\s\+\([-+*]\s\+\|(\?.\+[).]\)\@[[:punct:]]*\)\@<="[[:blank:][:punct:]\n]\@=/  containedin=pandocEmphasis,pandocStrong,pandocUListItem,pandocListItem,pandocListItemContinuation display', 'conceal cchar=”')
-endif
-" }}}3
-
-" Hrule: {{{3
-syn match pandocHRule /^\s*\([*\-_]\)\s*\%(\1\s*\)\{2,}$/ display
-" }}}3
-
-" Backslashes: {{{3
-if g:pandoc#syntax#conceal#backslash == 1
-    syn match pandocBackslash /\v\\@
+
+scriptencoding utf-8
+
+syntax clear
+
+lua include("commonmark")
diff --git a/syntax/pandoc_legacy.vim b/syntax/pandoc_legacy.vim
new file mode 100644
index 0000000..9d318ef
--- /dev/null
+++ b/syntax/pandoc_legacy.vim
@@ -0,0 +1,699 @@
+" vim: set fdm=marker foldlevel=0:
+"
+" Vim syntax file
+"
+" Language: Pandoc (superset of Markdown)
+" Maintainer: Felipe Morales 
+" Maintainer: Caleb Maclennan 
+" Contributor: David Sanson 
+" Contributor: Jorge Israel Peña 
+" OriginalAuthor: Jeremy Schultz 
+" Version: 5.0
+
+scriptencoding utf-8
+
+" Configuration: {{{1
+"
+" use conceal? {{{2
+if !exists('g:pandoc#syntax#conceal#use')
+    if v:version < 703
+        let g:pandoc#syntax#conceal#use = 0
+    else
+        let g:pandoc#syntax#conceal#use = 1
+    endif
+else
+    " exists, but we cannot use it, disable anyway
+    if v:version < 703
+        let g:pandoc#syntax#conceal#use = 0
+    endif
+endif
+"}}}2
+
+" what groups not to use conceal in. works as a blacklist {{{2
+if !exists('g:pandoc#syntax#conceal#blacklist')
+    let g:pandoc#syntax#conceal#blacklist = []
+endif
+" }}}2
+
+" cchars used in conceal rules {{{2
+" utf-8 defaults (preferred)
+if &encoding ==# 'utf-8'
+    let s:cchars = {
+                \'newline': '↵',
+                \'image': '▨',
+                \'super': 'ⁿ',
+                \'sub': 'ₙ',
+                \'strike': 'x̶',
+                \'atx': '§',
+                \'codelang': 'λ',
+                \'codeend': '—',
+                \'abbrev': '→',
+                \'footnote': '†',
+                \'definition': ' ',
+                \'li': '•',
+                \'html_c_s': '‹',
+                \'html_c_e': '›'}
+else
+    " ascii defaults
+    let s:cchars = {
+                \'newline': ' ',
+                \'image': 'i',
+                \'super': '^',
+                \'sub': '_',
+                \'strike': '~',
+                \'atx': '#',
+                \'codelang': 'l',
+                \'codeend': '-',
+                \'abbrev': 'a',
+                \'footnote': 'f',
+                \'definition': ' ',
+                \'li': '*',
+                \'html_c_s': '+',
+                \'html_c_e': '+'}
+endif
+" }}}2
+
+" if the user has a dictionary with replacements for the default cchars, use those {{{2
+if exists('g:pandoc#syntax#conceal#cchar_overrides')
+    let s:cchars = extend(s:cchars, g:pandoc#syntax#conceal#cchar_overrides)
+endif
+" }}}2
+
+"should the urls in links be concealed? {{{2
+if !exists('g:pandoc#syntax#conceal#urls')
+    let g:pandoc#syntax#conceal#urls = 0
+endif
+" should backslashes in escapes be concealed? {{{2
+if !exists('g:pandoc#syntax#conceal#backslash')
+    let g:pandoc#syntax#conceal#backslash = 0
+endif
+" }}}2
+
+" leave specified codeblocks as Normal (i.e. 'unhighlighted') {{{2
+if !exists('g:pandoc#syntax#codeblocks#ignore')
+    let g:pandoc#syntax#codeblocks#ignore = []
+endif
+" }}}2
+
+" use embedded highlighting for delimited codeblocks where a language is specifed. {{{2
+if !exists('g:pandoc#syntax#codeblocks#embeds#use')
+    let g:pandoc#syntax#codeblocks#embeds#use = 1
+endif
+" }}}2
+
+" for what languages and using what vim syntax files highlight those embeds. {{{2
+" defaults to None.
+if !exists('g:pandoc#syntax#codeblocks#embeds#langs')
+    let g:pandoc#syntax#codeblocks#embeds#langs = []
+endif
+" }}}2
+
+" use italics ? {{{2
+if !exists('g:pandoc#syntax#style#emphases')
+    let g:pandoc#syntax#style#emphases = 1
+endif
+" if 0, we don't conceal the emphasis marks, otherwise there wouldn't be a way
+" to tell where the styles apply.
+if g:pandoc#syntax#style#emphases == 0
+    call add(g:pandoc#syntax#conceal#blacklist, 'block')
+endif
+" }}}2
+
+" underline subscript, superscript and strikeout? {{{2
+if !exists('g:pandoc#syntax#style#underline_special')
+    let g:pandoc#syntax#style#underline_special = 1
+endif
+" }}}2
+
+" protect code blocks? {{{2
+if !exists('g:pandoc#syntax#protect#codeblocks')
+    let g:pandoc#syntax#protect#codeblocks = 1
+endif
+" }}}2
+
+" use color column? {{{2
+if !exists('g:pandoc#syntax#colorcolumn')
+    let g:pandoc#syntax#colorcolumn = 0
+endif
+" }}}2
+
+" highlight new lines? {{{2
+if !exists('g:pandoc#syntax#newlines')
+    let g:pandoc#syntax#newlines = 1
+endif
+" }}}
+
+" detect roman-numeral list items? {{{2
+if !exists('g:pandoc#syntax#roman_lists')
+    let g:pandoc#syntax#roman_lists = 0
+endif
+" }}}2
+
+" disable syntax highlighting for definition lists? (better performances) {{{2
+if !exists('g:pandoc#syntax#use_definition_lists')
+    let g:pandoc#syntax#use_definition_lists = 1
+endif
+" }}}2
+
+" }}}1
+
+" Functions: {{{1
+" EnableEmbedsforCodeblocksWithLang {{{2
+function! EnableEmbedsforCodeblocksWithLang(entry)
+    " prevent embedded language syntaxes from changing 'foldmethod' 
+    if has('folding')
+        let s:foldmethod = &l:foldmethod
+    endif
+
+    try
+        let s:langname = matchstr(a:entry, '^[^=]*')
+        let s:langsyntaxfile = matchstr(a:entry, '[^=]*$')
+        unlet! b:current_syntax
+        exe 'syn include @'.toupper(s:langname).' syntax/'.s:langsyntaxfile.'.vim'
+        exe 'syn region pandocDelimitedCodeBlock_' . s:langname . ' start=/\(\_^\([ ]\{4,}\|\t\)\=\(`\{3,}`*\|\~\{3,}\~*\)\s*\%({[^.]*\.\)\=' . s:langname . '\>.*\n\)\@<=\_^/' .
+                    \' end=/\_$\n\(\([ ]\{4,}\|\t\)\=\(`\{3,}`*\|\~\{3,}\~*\)\_$\n\_$\)\@=/ contained containedin=pandocDelimitedCodeBlock' .
+                    \' contains=@' . toupper(s:langname)
+        exe 'syn region pandocDelimitedCodeBlockinBlockQuote_' . s:langname . ' start=/>\s\(`\{3,}`*\|\~\{3,}\~*\)\s*\%({[^.]*\.\)\=' . s:langname . '\>/' .
+                    \ ' end=/\(`\{3,}`*\|\~\{3,}\~*\)/ contained containedin=pandocDelimitedCodeBlock' .
+                    \' contains=@' . toupper(s:langname) .
+                    \',pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd,pandodDelimitedCodeblockLang,pandocBlockQuoteinDelimitedCodeBlock'
+    catch /E484/
+      echo "No syntax file found for '" . s:langsyntaxfile . "'"
+    endtry
+
+    if exists('s:foldmethod') && s:foldmethod !=# &l:foldmethod
+        let &l:foldmethod = s:foldmethod
+    endif
+endfunction
+" }}}2
+
+" DisableEmbedsforCodeblocksWithLang {{{2
+function! DisableEmbedsforCodeblocksWithLang(langname)
+    try
+      exe 'syn clear pandocDelimitedCodeBlock_'.a:langname
+      exe 'syn clear pandocDelimitedCodeBlockinBlockQuote_'.a:langname
+    catch /E28/
+      echo "No existing highlight definitions found for '" . a:langname . "'"
+    endtry
+endfunction
+" }}}2
+
+" WithConceal {{{2
+function! s:WithConceal(rule_group, rule, conceal_rule)
+    let l:rule_tail = ''
+    if g:pandoc#syntax#conceal#use != 0
+        if index(g:pandoc#syntax#conceal#blacklist, a:rule_group) == -1
+            let l:rule_tail = ' ' . a:conceal_rule
+        endif
+    endif
+    execute a:rule . l:rule_tail
+endfunction
+" }}}2
+
+" }}}1
+
+" Commands: {{{1
+command! -buffer -nargs=1 -complete=syntax PandocHighlight call EnableEmbedsforCodeblocksWithLang()
+command! -buffer -nargs=1 -complete=syntax PandocUnhighlight call DisableEmbedsforCodeblocksWithLang()
+" }}}1
+
+" BASE:
+syntax clear
+syntax spell toplevel
+" apply extra settings: {{{1
+if g:pandoc#syntax#colorcolumn == 1
+    exe 'setlocal colorcolumn='.string(&textwidth+5)
+elseif g:pandoc#syntax#colorcolumn == 2
+    exe 'setlocal colorcolumn='.join(range(&textwidth+5, 2*&columns), ',')
+endif
+if g:pandoc#syntax#conceal#use != 0
+    setlocal conceallevel=2
+endif
+" }}}1
+
+" Syntax Rules: {{{1
+
+" Embeds: {{{2
+
+" prevent embedded language syntaxes from changing 'foldmethod' 
+if has('folding')
+    let s:foldmethod = &l:foldmethod
+endif
+
+" HTML: {{{3
+" Set embedded HTML highlighting
+syn include @HTML syntax/html.vim
+syn match pandocHTML /<\/\?\a.\{-}>/ contains=@HTML
+" Support HTML multi line comments
+syn region pandocHTMLComment start=// keepend contains=pandocHTMLCommentStart,pandocHTMLCommentEnd
+call s:WithConceal('html_c_s', 'syn match pandocHTMLCommentStart // contained', 'conceal cchar='.s:cchars['html_c_e'])
+" }}}3
+
+" LaTeX: {{{3
+" Set embedded LaTex (pandoc extension) highlighting
+" Unset current_syntax so the 2nd include will work
+unlet b:current_syntax
+syn include @LATEX syntax/tex.vim
+syn region pandocLaTeXInlineMath start=/\v\\@.*\n\(.*\n\@1/ contained containedin=pandocEmphasis,pandocStrong,pandocPCite,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocUListItem,pandocNoFormatted
+" }}}2
+
+" Code Blocks: {{{2
+if g:pandoc#syntax#protect#codeblocks == 1
+    syn match pandocCodeblock /\([ ]\{4}\|\t\).*$/
+endif
+syn region pandocCodeBlockInsideIndent   start=/\(\(\d\|\a\|*\).*\n\)\@/ contains=NONE
+" }}}3
+
+" }}}2
+
+" Citations: {{{2
+" parenthetical citations
+syn match pandocPCite "\^\@~/]*.\{-}\]" contains=pandocEmphasis,pandocStrong,pandocLatex,pandocCiteKey,@Spell,pandocAmpersandEscape display
+" in-text citations with location
+syn match pandocICite "@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\s\[.\{-1,}\]" contains=pandocCiteKey,@Spell display
+" cite keys
+syn match pandocCiteKey /\(-\=@[[:alnum:]_][[:digit:][:lower:][:upper:]_:.#$%&\-+?<>~/]*\)/ containedin=pandocPCite,pandocICite contains=@NoSpell display
+syn match pandocCiteAnchor /[-@]/ contained containedin=pandocCiteKey display
+syn match pandocCiteLocator /[\[\]]/ contained containedin=pandocPCite,pandocICite
+" }}}2
+
+" Text Styles: {{{2
+
+" Emphasis: {{{3
+call s:WithConceal('block', 'syn region pandocEmphasis matchgroup=pandocOperator start=/\\\@1.*\n\|^\s*\n\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,pandocEscapedDollar,@Spell,pandocAmpersandEscape,pandocReferenceLabel,pandocReferenceURL display
+syn match pandocAtxHeaderMark /\(^#\{1,6}\|\\\@/ contained containedin=pandocGridTableHeader,pandocPipeTableHeader contains=@Spell
+" }}}2
+
+" Delimited Code Blocks: {{{2
+" this is here because we can override strikeouts and subscripts
+syn region pandocDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\{4,}\|\t\)\=\~\{3,}\~*\)/ end=/^\z1\~*/ skipnl contains=pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd keepend
+syn region pandocDelimitedCodeBlock start=/^\(>\s\)\?\z(\([ ]\{4,}\|\t\)\=`\{3,}`*\)/ end=/^\z1`*/ skipnl contains=pandocDelimitedCodeBlockStart,pandocDelimitedCodeBlockEnd keepend
+call s:WithConceal('codeblock_start', 'syn match pandocDelimitedCodeBlockStart /\(\_^\n\_^\(>\s\)\?\([ ]\{4,}\|\t\)\=\)\@<=\(\~\{3,}\~*\|`\{3,}`*\)/ contained containedin=pandocDelimitedCodeBlock nextgroup=pandocDelimitedCodeBlockLanguage', 'conceal cchar='.s:cchars['codelang'])
+syn match pandocDelimitedCodeBlockLanguage /\(\s\?\)\@<=.\+\(\_$\)\@=/ contained
+call s:WithConceal('codeblock_delim', 'syn match pandocDelimitedCodeBlockEnd /\(`\{3,}`*\|\~\{3,}\~*\)\(\_$\n\(>\s\)\?\_$\)\@=/ contained containedin=pandocDelimitedCodeBlock', 'conceal cchar='.s:cchars['codeend'])
+syn match pandocBlockQuoteinDelimitedCodeBlock '^>' contained containedin=pandocDelimitedCodeBlock
+syn match pandocCodePre /
.\{-}<\/pre>/ skipnl
+syn match pandocCodePre /.\{-}<\/code>/ skipnl
+
+" enable highlighting for embedded region in codeblocks if there exists a
+" g:pandoc#syntax#codeblocks#embeds#langs *list*.
+"
+" entries in this list are the language code interpreted by pandoc,
+" if this differs from the name of the vim syntax file, append =vimname
+" e.g. let g:pandoc#syntax#codeblocks#embeds#langs = ["haskell", "literatehaskell=lhaskell"]
+"
+if g:pandoc#syntax#codeblocks#embeds#use != 0
+    for l in g:pandoc#syntax#codeblocks#embeds#langs
+      call EnableEmbedsforCodeblocksWithLang(l)
+    endfor
+endif
+" }}}2
+
+" Abbreviations: {{{2
+syn region pandocAbbreviationDefinition start=/^\*\[.\{-}\]:\s*/ end='$' contains=pandocNoFormatted,@Spell,pandocAmpersandEscape
+call s:WithConceal('abbrev', 'syn match pandocAbbreviationSeparator /:/ contained containedin=pandocAbbreviationDefinition', 'conceal cchar='.s:cchars['abbrev'])
+syn match pandocAbbreviation /\*\[.\{-}\]/ contained containedin=pandocAbbreviationDefinition
+call s:WithConceal('abbrev', 'syn match pandocAbbreviationHead /\*\[/ contained containedin=pandocAbbreviation', 'conceal')
+call s:WithConceal('abbrev', 'syn match pandocAbbreviationTail /\]/ contained containedin=pandocAbbreviation', 'conceal')
+" }}}2
+
+" Footnotes: {{{2
+" we put these here not to interfere with superscripts.
+syn match pandocFootnoteID /\[\^[^\]]\+\]/ nextgroup=pandocFootnoteDef
+
+"   Inline footnotes
+syn region pandocFootnoteDef start=/\^\[/ skip=/\[.\{-}]/ end=/\]/ contains=pandocReferenceLabel,pandocReferenceURL,pandocLatex,pandocPCite,pandocCiteKey,pandocStrong,pandocEmphasis,pandocStrongEmphasis,pandocNoFormatted,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocEnDash,pandocEmDash,pandocEllipses,pandocBeginQuote,pandocEndQuote,@Spell,pandocAmpersandEscape skipnl keepend
+call s:WithConceal('footnote', 'syn match pandocFootnoteDefHead /\^\[/ contained containedin=pandocFootnoteDef', 'conceal cchar='.s:cchars['footnote'])
+call s:WithConceal('footnote', 'syn match pandocFootnoteDefTail /\]/ contained containedin=pandocFootnoteDef', 'conceal')
+
+" regular footnotes
+syn region pandocFootnoteBlock start=/\[\^.\{-}\]:\s*\n*/ end=/^\n^\s\@!/ contains=pandocReferenceLabel,pandocReferenceURL,pandocLatex,pandocPCite,pandocCiteKey,pandocStrong,pandocEmphasis,pandocNoFormatted,pandocSuperscript,pandocSubscript,pandocStrikeout,pandocEnDash,pandocEmDash,pandocNewLine,pandocStrongEmphasis,pandocEllipses,pandocBeginQuote,pandocEndQuote,pandocLaTeXInlineMath,pandocEscapedDollar,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXRegion,pandocAmpersandEscape,@Spell skipnl
+syn match pandocFootnoteBlockSeparator /:/ contained containedin=pandocFootnoteBlock
+syn match pandocFootnoteID /\[\^.\{-}\]/ contained containedin=pandocFootnoteBlock
+call s:WithConceal('footnote', 'syn match pandocFootnoteIDHead /\[\^/ contained containedin=pandocFootnoteID', 'conceal cchar='.s:cchars['footnote'])
+call s:WithConceal('footnote', 'syn match pandocFootnoteIDTail /\]/ contained containedin=pandocFootnoteID', 'conceal')
+" }}}2
+
+" List Items: {{{2
+" Unordered lists
+syn match pandocUListItem /^>\=\s*[*+-]\s\+-\@!.*$/ nextgroup=pandocUListItem,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocDelimitedCodeBlock,pandocListItemContinuation contains=@Spell,pandocEmphasis,pandocStrong,pandocNoFormatted,pandocStrikeout,pandocSubscript,pandocSuperscript,pandocStrongEmphasis,pandocStrongEmphasis,pandocPCite,pandocICite,pandocCiteKey,pandocReferenceLabel,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocReferenceURL,pandocAutomaticLink,pandocFootnoteDef,pandocFootnoteBlock,pandocFootnoteID,pandocAmpersandEscape skipempty display
+call s:WithConceal('list', 'syn match pandocUListItemBullet /^>\=\s*\zs[*+-]/ contained containedin=pandocUListItem', 'conceal cchar='.s:cchars['li'])
+
+" Ordered lists
+syn match pandocListItem /^\s*(\?\(\d\+\|\l\|\#\|@\)[.)].*$/ nextgroup=pandocListItem,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocDelimitedCodeBlock,pandocListItemContinuation contains=@Spell,pandocEmphasis,pandocStrong,pandocNoFormatted,pandocStrikeout,pandocSubscript,pandocSuperscript,pandocStrongEmphasis,pandocStrongEmphasis,pandocPCite,pandocICite,pandocCiteKey,pandocReferenceLabel,pandocLaTeXCommand,pandocLaTeXMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocAutomaticLink,pandocFootnoteDef,pandocFootnoteBlock,pandocFootnoteID,pandocAmpersandEscape skipempty display
+
+" support for roman numerals up to 'c'
+if g:pandoc#syntax#roman_lists != 0
+    syn match pandocListItem /^\s*(\?x\=l\=\(i\{,3}[vx]\=\)\{,3}c\{,3}[.)].*$/ nextgroup=pandocListItem,pandocMathBlock,pandocLaTeXInlineMath,pandocEscapedDollar,pandocDelimitedCodeBlock,pandocListItemContinuation,pandocAutomaticLink skipempty display
+endif
+syn match pandocListItemBullet /^(\?.\{-}[.)]/ contained containedin=pandocListItem
+syn match pandocListItemBulletId /\(\d\+\|\l\|\#\|@.\{-}\|x\=l\=\(i\{,3}[vx]\=\)\{,3}c\{,3}\)/ contained containedin=pandocListItemBullet
+
+syn match pandocListItemContinuation /^\s\+\([-+*]\s\+\|(\?.\+[).]\)\@[[:punct:]]*\)\@<="[[:blank:][:punct:]\n]\@=/  containedin=pandocEmphasis,pandocStrong,pandocUListItem,pandocListItem,pandocListItemContinuation display', 'conceal cchar=”')
+endif
+" }}}3
+
+" Hrule: {{{3
+syn match pandocHRule /^\s*\([*\-_]\)\s*\%(\1\s*\)\{2,}$/ display
+" }}}3
+
+" Backslashes: {{{3
+if g:pandoc#syntax#conceal#backslash == 1
+    syn match pandocBackslash /\v\\@