From b32e3b0dec8a45d0a413d5382198145484400485 Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Thu, 9 Jan 2025 13:03:41 -0500 Subject: [PATCH] chore: update comrak to v0.33.0 - added the Raw node --- lib/mdex/document.ex | 14 ++++++++++++++ mix.exs | 1 + native/comrak_nif/Cargo.lock | 14 ++++++-------- native/comrak_nif/Cargo.toml | 4 ++-- native/comrak_nif/src/types/document.rs | 18 ++++++++++++++++++ test/html_format_test.exs | 12 ++++++++++++ 6 files changed, 53 insertions(+), 10 deletions(-) diff --git a/lib/mdex/document.ex b/lib/mdex/document.ex index 7569c51..9373660 100644 --- a/lib/mdex/document.ex +++ b/lib/mdex/document.ex @@ -241,6 +241,7 @@ defmodule MDEx.Document do | MDEx.LineBreak.t() | MDEx.Code.t() | MDEx.HtmlInline.t() + | MDEx.Raw.t() | MDEx.Emph.t() | MDEx.Strong.t() | MDEx.Strikethrough.t() @@ -295,6 +296,7 @@ defmodule MDEx.Document do MDEx.LineBreak, MDEx.Code, MDEx.HtmlInline, + MDEx.Raw, MDEx.Emph, MDEx.Strong, MDEx.Strikethrough, @@ -695,6 +697,16 @@ defmodule MDEx.HtmlInline do use MDEx.Document.Access end +defmodule MDEx.Raw do + @moduledoc """ + A Raw output node. This will be inserted verbatim into CommonMark and HTML output. It can only be created programmatically, and is never parsed from input. + """ + + @type t :: %__MODULE__{literal: String.t()} + defstruct literal: "" + use MDEx.Document.Access +end + defmodule MDEx.Emph do @moduledoc """ Emphasis. @@ -886,6 +898,7 @@ defimpl Enumerable, MDEx.LineBreak, MDEx.Code, MDEx.HtmlInline, + MDEx.Raw, MDEx.Emph, MDEx.Strong, MDEx.Strikethrough, @@ -970,6 +983,7 @@ defimpl String.Chars, MDEx.LineBreak, MDEx.Code, MDEx.HtmlInline, + MDEx.Raw, MDEx.Emph, MDEx.Strong, MDEx.Strikethrough, diff --git a/mix.exs b/mix.exs index 52de878..21c4855 100644 --- a/mix.exs +++ b/mix.exs @@ -90,6 +90,7 @@ defmodule MDEx.MixProject do MDEx.LineBreak, MDEx.Code, MDEx.HtmlInline, + MDEx.Raw, MDEx.Emph, MDEx.Strong, MDEx.Strikethrough, diff --git a/native/comrak_nif/Cargo.lock b/native/comrak_nif/Cargo.lock index e5af5f2..d27661c 100644 --- a/native/comrak_nif/Cargo.lock +++ b/native/comrak_nif/Cargo.lock @@ -207,9 +207,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.24" +version = "4.5.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9560b07a799281c7e0958b9296854d6fafd4c5f31444a7e5bb1ad6dde5ccf1bd" +checksum = "b95dca1b68188a08ca6af9d96a6576150f598824bdb528c1190460c2940a0b48" dependencies = [ "clap_builder", "clap_derive", @@ -217,9 +217,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.24" +version = "4.5.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "874e0dd3eb68bf99058751ac9712f622e61e6f393a94f7128fa26e3f02f5c7cd" +checksum = "9ab52925392148efd3f7562f2136a81ffb778076bcc85727c6e020d6dd57cf15" dependencies = [ "anstream", "anstyle", @@ -254,9 +254,9 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "comrak" -version = "0.31.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453dcb42e33f7b474d7e0db12e0b8d82802c88f35cf5a1d8c297d0dfcecb154f" +checksum = "39bff2cbb80102771ca62bd2375bc6f6611dc1493373440b23aa08a155538708" dependencies = [ "bon", "caseless", @@ -264,8 +264,6 @@ dependencies = [ "emojis", "entities", "memchr", - "once_cell", - "regex", "shell-words", "slug", "syntect", diff --git a/native/comrak_nif/Cargo.toml b/native/comrak_nif/Cargo.toml index 61577c8..05841f3 100644 --- a/native/comrak_nif/Cargo.toml +++ b/native/comrak_nif/Cargo.toml @@ -16,7 +16,7 @@ rustler = { version = "0.33", features = [ "serde", ] } serde = "1.0" -comrak = { version = "0.31", features = ["shortcodes"] } +comrak = { version = "0.33", features = ["shortcodes"] } ammonia = "4.0" phf = { version = "0.11", features = ["macros"] } tree-sitter = "0.20" @@ -25,6 +25,7 @@ v_htmlescape = "0.15" autumn = { path = "vendor/autumn" } log = "0.4" lazy_static = "1.5" +typed-arena = "2.0.2" inkjet = { version = "0.10.5", default-features = false, features = [ "html", "language-bash", @@ -81,7 +82,6 @@ inkjet = { version = "0.10.5", default-features = false, features = [ "language-yaml", "language-zig", ] } -typed-arena = "2.0.2" [features] default = ["nif_version_2_15"] diff --git a/native/comrak_nif/src/types/document.rs b/native/comrak_nif/src/types/document.rs index 67851a7..c93ed72 100644 --- a/native/comrak_nif/src/types/document.rs +++ b/native/comrak_nif/src/types/document.rs @@ -44,6 +44,7 @@ pub enum NewNode { LineBreak(ExLineBreak), Code(ExCode), HtmlInline(ExHtmlInline), + Raw(ExRaw), Emph(ExEmph), Strong(ExStrong), Strikethrough(ExStrikethrough), @@ -89,6 +90,7 @@ impl From for NodeValue { NewNode::LineBreak(n) => n.into(), NewNode::Code(n) => n.into(), NewNode::HtmlInline(n) => n.into(), + NewNode::Raw(n) => n.into(), NewNode::Emph(n) => n.into(), NewNode::Strong(n) => n.into(), NewNode::Strikethrough(n) => n.into(), @@ -533,6 +535,18 @@ impl From for NodeValue { } } +#[derive(Debug, Clone, PartialEq, NifStruct)] +#[module = "MDEx.Raw"] +pub struct ExRaw { + pub literal: String, +} + +impl From for NodeValue { + fn from(node: ExRaw) -> Self { + NodeValue::Raw(node.literal.to_string()) + } +} + #[derive(Debug, Clone, PartialEq, NifStruct)] #[module = "MDEx.Emph"] pub struct ExEmph { @@ -941,6 +955,10 @@ pub fn comrak_ast_to_ex_document<'a>(node: &'a AstNode<'a>) -> NewNode { literal: literal.to_string(), }), + NodeValue::Raw(ref literal) => NewNode::Raw(ExRaw { + literal: literal.to_string(), + }), + NodeValue::Emph => NewNode::Emph(ExEmph { nodes: children }), NodeValue::Strong => NewNode::Strong(ExStrong { nodes: children }), diff --git a/test/html_format_test.exs b/test/html_format_test.exs index b249eb3..41bff8e 100644 --- a/test/html_format_test.exs +++ b/test/html_format_test.exs @@ -379,4 +379,16 @@ defmodule MDEx.HTMLFormatTest do test "subscript" do assert_format("H~2~O", "

H2O

", subscript: true) end + + test "raw" do + ast = %MDEx.Document{ + nodes: [ + %MDEx.Raw{ + literal: "{ }" + } + ] + } + + assert MDEx.to_html(ast) == {:ok, "{ }"} + end end