Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
liamwhite committed Nov 21, 2024
2 parents 5c0a73d + 9a6715c commit d0c276e
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 157 deletions.
14 changes: 0 additions & 14 deletions lib/philomena/markdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ defmodule Philomena.Markdown do
def to_html_unsafe(text, replacements),
do: Philomena.Native.markdown_to_html_unsafe(text, replacements)

@doc """
Places a Markdown document into its canonical CommonMark form.
"""
@spec to_cm(String.t()) :: String.t()
def to_cm(text),
do: Philomena.Native.markdown_to_cm(text)

@doc """
Determines whether a Markdown document uses a subscript operator, for migration.
"""
@spec has_subscript?(String.t()) :: boolean()
def has_subscript?(text),
do: Philomena.Native.markdown_has_subscript(text)

@doc """
Escapes special characters in text which is to be rendered as Markdown.
"""
Expand Down
82 changes: 0 additions & 82 deletions lib/philomena/markdown/subscript_migrator.ex

This file was deleted.

6 changes: 0 additions & 6 deletions lib/philomena/native.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ defmodule Philomena.Native do
@spec markdown_to_html_unsafe(String.t(), %{String.t() => String.t()}) :: String.t()
def markdown_to_html_unsafe(_text, _replacements), do: :erlang.nif_error(:nif_not_loaded)

@spec markdown_to_cm(String.t()) :: String.t()
def markdown_to_cm(_text), do: :erlang.nif_error(:nif_not_loaded)

@spec markdown_has_subscript(String.t()) :: boolean()
def markdown_has_subscript(_text), do: :erlang.nif_error(:nif_not_loaded)

@spec camo_image_url(String.t()) :: String.t()
def camo_image_url(_uri), do: :erlang.nif_error(:nif_not_loaded)

Expand Down
4 changes: 0 additions & 4 deletions lib/philomena/release.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ defmodule Philomena.Release do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end

def migrate_markdown(type, id_start, id_end) do
Philomena.Markdown.SubscriptMigrator.migrate(type, id_start, id_end)
end

def update_channels do
start_app()
Philomena.Channels.update_tracked_channels!()
Expand Down
2 changes: 1 addition & 1 deletion native/philomena/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion native/philomena/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["dylib"]

[dependencies]
base64 = "0.21"
comrak = { git = "https://github.com/philomena-dev/comrak", branch = "philomena-0.29.1", default-features = false }
comrak = { git = "https://github.com/philomena-dev/comrak", branch = "philomena-0.29.2", default-features = false }
http = "0.2"
jemallocator = { version = "0.5.0", features = ["disable_initial_exec_tls"] }
regex = "1"
Expand Down
15 changes: 2 additions & 13 deletions native/philomena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ static GLOBAL: Jemalloc = Jemalloc;
rustler::init! {
"Elixir.Philomena.Native",
[
markdown_to_html, markdown_to_html_unsafe, markdown_to_cm,
markdown_has_subscript, camo_image_url, zip_open_writer,
zip_start_file, zip_write, zip_finish
markdown_to_html, markdown_to_html_unsafe, camo_image_url,
zip_open_writer, zip_start_file, zip_write, zip_finish
],
load = load
}
Expand All @@ -40,16 +39,6 @@ fn markdown_to_html_unsafe(input: &str, reps: HashMap<String, String>) -> String
markdown::to_html_unsafe(input, reps)
}

#[rustler::nif(schedule = "DirtyCpu")]
fn markdown_to_cm(input: &str) -> String {
markdown::to_cm(input)
}

#[rustler::nif(schedule = "DirtyCpu")]
fn markdown_has_subscript(input: &str) -> bool {
markdown::has_subscript(input)
}

// Camo NIF wrappers.

#[rustler::nif]
Expand Down
37 changes: 2 additions & 35 deletions native/philomena/src/markdown.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{camo, domains};
use comrak::nodes::AstNode;
use comrak::{Arena, Options};
use std::collections::{HashMap, VecDeque};
use comrak::Options;
use std::collections::HashMap;
use std::sync::Arc;

pub fn common_options() -> Options {
Expand All @@ -24,7 +23,6 @@ pub fn common_options() -> Options {
options.extension.greentext = true;
options.extension.subscript = true;
options.extension.philomena = true;
options.extension.alternate_subscript = true;
options.render.ignore_empty_links = true;
options.render.ignore_setext = true;

Expand Down Expand Up @@ -54,34 +52,3 @@ pub fn to_html_unsafe(input: &str, reps: HashMap<String, String>) -> String {

comrak::markdown_to_html(input, &options)
}

fn migration_options() -> Options {
let mut options = common_options();
options.extension.subscript = false;
options
}

pub fn to_cm(input: &str) -> String {
comrak::markdown_to_commonmark(input, &migration_options())
}

pub fn has_subscript(input: &str) -> bool {
let mut queue: VecDeque<&AstNode> = VecDeque::new();
let arena = Arena::new();

queue.push_back(comrak::parse_document(&arena, input, &migration_options()));

while let Some(front) = queue.pop_front() {
match &front.data.borrow().value {
comrak::nodes::NodeValue::Subscript => return true,
comrak::nodes::NodeValue::Strikethrough => return true,
_ => {}
}

for child in front.children() {
queue.push_back(child);
}
}

false
}
10 changes: 9 additions & 1 deletion native/philomena/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn html_opts_w(input: &str, expected: &str, options: &comrak::Options) {

#[test]
fn subscript() {
html("H%2%O\n", "<div class=\"paragraph\">H<sub>2</sub>O</div>\n");
html("H~2~O\n", "<div class=\"paragraph\">H<sub>2</sub>O</div>\n");
}

#[test]
Expand All @@ -56,6 +56,14 @@ fn subscript_autolink_interaction() {
);
}

#[test]
fn underscore_autolink_interaction() {
html(
"https://example.com/x_",
"<div class=\"paragraph\"><a href=\"https://example.com/x_\">https://example.com/x_</a></div>\n"
)
}

#[test]
fn spoiler() {
html(
Expand Down

0 comments on commit d0c276e

Please sign in to comment.