Page MenuHomePhorge

No OneTemporary

Size
24 KB
Referenced Files
None
Subscribers
None
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6492370..d330df7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,40 +1,40 @@
# SPDX-FileCopyrightText: 2019-2022 Pleroma Authors
# SPDX-License-Identifier: LGPL-3.0-only
-image: elixir:1.7
+image: elixir:1.15
variables:
MIX_ENV: test
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- deps
- _build
stages:
- test
- publish
before_script:
- mix local.hex --force
- mix local.rebar --force
- mix deps.get
- mix compile --force
lint:
stage: test
script:
- mix format --check-formatted
unit-testing:
stage: test
coverage: '/(\d+\.\d+\%) \| Total/'
script:
- mix test --trace --preload-modules --cover
analysis:
stage: test
script:
- mix credo --strict --only=warnings,todo,fixme,consistency,readability
diff --git a/config/config.exs b/config/config.exs
index 569ef0b..ead33bc 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -1,33 +1,33 @@
# SPDX-FileCopyrightText: 2019-2022 Pleroma Authors
# SPDX-License-Identifier: LGPL-3.0-only
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
-use Mix.Config
+import Config
# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.
# You can configure your application as:
#
# config :bbcode, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:bbcode, :key)
#
# You can also configure a 3rd-party app:
#
# config :logger, level: :info
#
# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env()}.exs"
diff --git a/lib/bbcode/generator.ex b/lib/bbcode/generator.ex
index 44e095f..7e576b0 100644
--- a/lib/bbcode/generator.ex
+++ b/lib/bbcode/generator.ex
@@ -1,76 +1,79 @@
# SPDX-FileCopyrightText: 2019-2022 Pleroma Authors
# SPDX-License-Identifier: LGPL-3.0-only
defmodule BBCode.Generator do
@moduledoc """
Generate HTML from BBCode fragments in AST form.
The BBCode syntax supported is described at [bbcode.org][bbcode].
[bbcode]: https://www.bbcode.org/reference.php
"""
defp start_tag(tagname), do: Enum.join(["<", tagname, ">"])
defp end_tag(tagname), do: Enum.join(["</", tagname, ">"])
defp simple_tag(tagname, subtree) do
{:ok, text} = reduce_subtree(subtree)
{:ok, [start_tag(tagname), text, end_tag(tagname)] |> Enum.join()}
end
defp link_tag(url), do: Enum.join(["<a href=\"", url, "\">"])
defp reduce_subtree({:b, subtree}), do: simple_tag("strong", subtree)
defp reduce_subtree({:i, subtree}), do: simple_tag("em", subtree)
defp reduce_subtree({:u, subtree}), do: simple_tag("u", subtree)
defp reduce_subtree({:s, subtree}), do: simple_tag("del", subtree)
defp reduce_subtree({:ul, subtree}), do: simple_tag("ul", subtree)
defp reduce_subtree({:ol, subtree}), do: simple_tag("ol", subtree)
defp reduce_subtree({:li, subtree}), do: simple_tag("li", subtree)
defp reduce_subtree({:code, subtree}), do: simple_tag("pre", subtree)
defp reduce_subtree({:quote, subtree}), do: simple_tag("blockquote", subtree)
defp reduce_subtree({:table, subtree}), do: simple_tag("table", subtree)
defp reduce_subtree({:tr, subtree}), do: simple_tag("tr", subtree)
defp reduce_subtree({:th, subtree}), do: simple_tag("th", subtree)
defp reduce_subtree({:td, subtree}), do: simple_tag("td", subtree)
+ defp reduce_subtree({:ruby, ruby, text}),
+ do: {:ok, "<ruby>#{text}<rp>(</rp><rt>#{ruby}</rt><rp>)</rp></ruby>"}
+
defp reduce_subtree({:url, text}),
do: {:ok, [link_tag(text), text, end_tag("a")] |> Enum.join()}
defp reduce_subtree({:url, address, text}),
do: {:ok, [link_tag(address), text, end_tag("a")] |> Enum.join()}
defp reduce_subtree({:img, address}),
do: {:ok, "<img src=\"#{address}\">"}
defp reduce_subtree({:img, width, height, address}),
do: {:ok, "<img src=\"#{address}\" width=\"#{width}\" height=\"#{height}\">"}
defp reduce_subtree({:br}), do: {:ok, "<br>"}
defp reduce_subtree(text_node) when is_binary(text_node),
do: {:ok, text_node}
defp reduce_subtree(children) when is_list(children) do
with {:ok, new_tree} <-
Enum.reduce_while(children, {:ok, []}, fn x, {:ok, acc} ->
with {:ok, new_tree} <- reduce_subtree(x) do
{:cont, {:ok, acc ++ [new_tree]}}
else
{:error, e} ->
{:halt, {:error, e}}
end
end) do
{:ok, Enum.join(new_tree)}
else
{:error, e} ->
{:error, e}
end
end
defp reduce_subtree(tree), do: {:error, "unknown input #{inspect(tree)}"}
def to_html(tree) when is_list(tree), do: reduce_subtree(tree)
def to_html(_), do: {:error, "not a valid tree"}
end
diff --git a/lib/bbcode/parser.ex b/lib/bbcode/parser.ex
index 995dbaf..3bb5fa0 100644
--- a/lib/bbcode/parser.ex
+++ b/lib/bbcode/parser.ex
@@ -1,217 +1,218 @@
# SPDX-FileCopyrightText: 2019-2022 Pleroma Authors
# SPDX-License-Identifier: LGPL-3.0-only
defmodule BBCode.Parser do
import NimbleParsec
@moduledoc """
Parse BBCode into an abstract tree.
"""
tag = utf8_string([?a..?z, ?A..?Z, ?0..?9], min: 1)
text = utf8_string([not: ?[, not: ?], not: ?\r, not: ?\n], min: 1)
end_tag =
ignore(string("[/"))
|> concat(tag)
|> ignore(string("]"))
# block tags
quote_tag = string("quote")
ul_tag = string("ul")
ol_tag = string("ol")
li_tag = string("li")
code_tag = string("code")
table_tag = string("table")
tr_tag = string("tr")
th_tag = string("th")
td_tag = string("td")
# span tags
b_tag = string("b")
i_tag = string("i")
u_tag = string("u")
s_tag = string("s")
url_tag = string("url")
+ ruby_tag = string("ruby")
img_tag = string("img")
# special tags
star_tag = ignore(string("[*]"))
# newline
newline = utf8_char([?\r, ?\n])
defcombinatorp(
:block_tag,
ignore(string("["))
|> choice([quote_tag, ul_tag, ol_tag, li_tag, code_tag, table_tag, tr_tag, th_tag, td_tag])
|> ignore(string("]"))
|> ignore(optional(utf8_string([?\n, ?\r], min: 1, max: 2)))
)
defcombinatorp(
:block_stanza,
parsec(:block_tag)
|> repeat(lookahead_not(string("[/")) |> choice([parsec(:child_stanza), text]))
|> wrap()
|> concat(end_tag)
|> ignore(optional(utf8_string([?\n, ?\r], min: 1, max: 2)))
|> post_traverse(:emit_tree_node)
)
defcombinatorp(
:span_tag,
ignore(string("["))
|> choice([url_tag, img_tag, b_tag, i_tag, u_tag, s_tag])
|> ignore(string("]"))
|> ignore(optional(utf8_string([?\n, ?\r], min: 1, max: 2)))
)
defcombinatorp(
:span_tag_with_property,
ignore(string("["))
- |> concat(url_tag)
+ |> choice([url_tag, ruby_tag])
|> ignore(string("="))
|> concat(text)
|> ignore(string("]"))
|> ignore(optional(utf8_string([?\n, ?\r], min: 1, max: 2)))
)
defcombinatorp(
:img_tag_with_size_property,
ignore(string("["))
|> concat(img_tag)
|> ignore(string("="))
|> integer(min: 1)
|> ignore(string("x"))
|> integer(min: 1)
|> ignore(string("]"))
|> ignore(optional(utf8_string([?\n, ?\r], min: 1, max: 2)))
)
defcombinatorp(
:span_stanza,
parsec(:span_tag)
|> repeat(lookahead_not(string("[/")) |> choice([parsec(:child_stanza), text]))
|> wrap()
|> concat(end_tag)
|> post_traverse(:emit_tree_node)
)
defcombinatorp(
:text_stanza,
text
|> wrap()
|> post_traverse(:emit_tree_node)
)
defcombinatorp(
:star_stanza,
star_tag
|> repeat(
lookahead_not(string("\n"))
|> choice([parsec(:child_stanza), text])
)
|> wrap()
|> concat(ignore(optional(utf8_string([?\n, ?\r], min: 1, max: 2))))
|> post_traverse(:emit_tree_node_star)
)
defcombinatorp(
:span_stanza_with_property,
parsec(:span_tag_with_property)
|> repeat(lookahead_not(string("[/")) |> choice([parsec(:child_stanza), text]))
|> wrap()
|> concat(end_tag)
|> post_traverse(:emit_tree_node_property)
)
defcombinatorp(
:img_stanza_with_size_property,
parsec(:img_tag_with_size_property)
|> repeat(lookahead_not(string("[/")) |> choice([parsec(:child_stanza), text]))
|> wrap()
|> concat(end_tag)
|> post_traverse(:emit_tree_node_size_property)
)
defcombinatorp(
:newline_stanza,
newline
|> post_traverse(:emit_tree_node_newline)
)
defcombinatorp(
:bracket_text_stanza,
string("[")
|> concat(text)
|> string("]")
|> wrap()
|> post_traverse(:emit_tree_node)
)
defcombinatorp(
:child_stanza,
choice([
parsec(:newline_stanza),
parsec(:star_stanza),
parsec(:block_stanza),
parsec(:img_stanza_with_size_property),
parsec(:span_stanza_with_property),
parsec(:span_stanza),
parsec(:bracket_text_stanza)
])
)
defcombinatorp(
:root_stanza,
choice([parsec(:child_stanza), parsec(:text_stanza)])
)
defparsecp(
:parse_tree,
repeat(lookahead_not(string("[/")) |> parsec(:root_stanza)) |> eos()
)
- defp emit_tree_node_newline(_rest, _args, context, _line, _offset),
- do: {[{:br}], context}
+ defp emit_tree_node_newline(rest, _args, context, _line, _offset),
+ do: {rest, [{:br}], context}
- defp emit_tree_node_star(_rest, [nodes], context, _line, _offset),
- do: {[{:li, nodes}], context}
+ defp emit_tree_node_star(rest, [nodes], context, _line, _offset),
+ do: {rest, [{:li, nodes}], context}
defp emit_tree_node_size_property(
- _rest,
+ rest,
[tag, [tag, width, height, inside]],
context,
_line,
_offset
),
- do: {[{String.to_atom(tag), width, height, inside}], context}
+ do: {rest, [{String.to_atom(tag), width, height, inside}], context}
- defp emit_tree_node_property(_rest, [tag, [tag, property, inside]], context, _line, _offset),
- do: {[{String.to_atom(tag), property, inside}], context}
+ defp emit_tree_node_property(rest, [tag, [tag, property, inside]], context, _line, _offset),
+ do: {rest, [{String.to_atom(tag), property, inside}], context}
- defp emit_tree_node_property(_rest, [tag, [tag, property | nodes]], context, _line, _offset),
- do: {[{String.to_atom(tag), property, nodes}], context}
+ defp emit_tree_node_property(rest, [tag, [tag, property | nodes]], context, _line, _offset),
+ do: {rest, [{String.to_atom(tag), property, nodes}], context}
- defp emit_tree_node(_rest, [tag, [tag, inside]], context, _line, _offset),
- do: {[{String.to_atom(tag), inside}], context}
+ defp emit_tree_node(rest, [tag, [tag, inside]], context, _line, _offset),
+ do: {rest, [{String.to_atom(tag), inside}], context}
- defp emit_tree_node(_rest, [tag, [tag | nodes]], context, _line, _offset),
- do: {[{String.to_atom(tag), nodes}], context}
+ defp emit_tree_node(rest, [tag, [tag | nodes]], context, _line, _offset),
+ do: {rest, [{String.to_atom(tag), nodes}], context}
- defp emit_tree_node(_rest, [[text]], context, _line, _offset),
- do: {[text], context}
+ defp emit_tree_node(rest, [[text]], context, _line, _offset),
+ do: {rest, [text], context}
- defp emit_tree_node(_rest, [["[", text, "]"]], context, _line, _offset),
- do: {["[" <> text <> "]"], context}
+ defp emit_tree_node(rest, [["[", text, "]"]], context, _line, _offset),
+ do: {rest, ["[" <> text <> "]"], context}
def parse(text) do
with {:ok, nodes, _, _, _, _} <- parse_tree(text) do
{:ok, nodes}
else
{:error, e, _, _, _, _} ->
{:error, e}
end
end
end
diff --git a/mix.exs b/mix.exs
index 71f79bd..659a39f 100644
--- a/mix.exs
+++ b/mix.exs
@@ -1,43 +1,43 @@
# SPDX-FileCopyrightText: 2019-2022 Pleroma Authors
# SPDX-License-Identifier: LGPL-3.0-only
defmodule BBCode.MixProject do
use Mix.Project
def project do
[
app: :bbcode,
name: "BBCode",
description: "BBCode parsing for Elixir",
version: "0.2.0",
- elixir: "~> 1.7",
+ elixir: "~> 1.15",
start_permanent: Mix.env() == :prod,
deps: deps(),
package: package()
]
end
def application do
[
extra_applications: [:logger]
]
end
defp deps do
[
- {:nimble_parsec, "~> 1.2"},
- {:credo, "~> 1.0", only: [:dev, :test], runtime: false},
- {:ex_doc, "~> 0.19", only: :dev, runtime: false},
- {:dialyxir, "~> 1.1.0", only: [:dev], runtime: false}
+ {:nimble_parsec, "~> 1.4"},
+ {:credo, "~> 1.7", only: [:dev, :test], runtime: false},
+ {:ex_doc, "~> 0.40", only: :dev, runtime: false},
+ {:dialyxir, "~> 1.4.0", only: [:dev], runtime: false}
]
end
defp package do
[
files: ["lib", "test", "mix.exs", "README.md"],
licenses: ["LGPL-3.0-only"],
links: %{"GitLab" => "https://git.pleroma.social/pleroma/bbcode"},
maintainers: []
]
end
end
diff --git a/mix.lock b/mix.lock
index 7b67952..1ef00b9 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,15 +1,15 @@
%{
- "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
- "credo": {:hex, :credo, "1.6.4", "ddd474afb6e8c240313f3a7b0d025cc3213f0d171879429bf8535d7021d9ad78", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "c28f910b61e1ff829bffa056ef7293a8db50e87f2c57a9b5c3f57eee124536b7"},
- "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
+ "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
+ "credo": {:hex, :credo, "1.7.16", "a9f1389d13d19c631cb123c77a813dbf16449a2aebf602f590defa08953309d4", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "d0562af33756b21f248f066a9119e3890722031b6d199f22e3cf95550e4f1579"},
+ "dialyxir": {:hex, :dialyxir, "1.4.7", "dda948fcee52962e4b6c5b4b16b2d8fa7d50d8645bbae8b8685c3f9ecb7f5f4d", [:mix], [{:erlex, ">= 0.2.8", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b34527202e6eb8cee198efec110996c25c5898f43a4094df157f8d28f27d9efe"},
"earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm"},
- "earmark_parser": {:hex, :earmark_parser, "1.4.20", "89970db71b11b6b89759ce16807e857df154f8df3e807b2920a8c39834a9e5cf", [:mix], [], "hexpm", "1eb0d2dabeeeff200e0d17dc3048a6045aab271f73ebb82e416464832eb57bdd"},
- "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
- "ex_doc": {:hex, :ex_doc, "0.28.2", "e031c7d1a9fc40959da7bf89e2dc269ddc5de631f9bd0e326cbddf7d8085a9da", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "51ee866993ffbd0e41c084a7677c570d0fc50cb85c6b5e76f8d936d9587fa719"},
- "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
- "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
- "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
- "makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
- "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
- "nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
+ "earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
+ "erlex": {:hex, :erlex, "0.2.8", "cd8116f20f3c0afe376d1e8d1f0ae2452337729f68be016ea544a72f767d9c12", [:mix], [], "hexpm", "9d66ff9fedf69e49dc3fd12831e12a8a37b76f8651dd21cd45fcf5561a8a7590"},
+ "ex_doc": {:hex, :ex_doc, "0.40.1", "67542e4b6dde74811cfd580e2c0149b78010fd13001fda7cfeb2b2c2ffb1344d", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "bcef0e2d360d93ac19f01a85d58f91752d930c0a30e2681145feea6bd3516e00"},
+ "file_system": {:hex, :file_system, "1.1.1", "31864f4685b0148f25bd3fbef2b1228457c0c89024ad67f7a81a3ffbc0bbad3a", [:mix], [], "hexpm", "7a15ff97dfe526aeefb090a7a9d3d03aa907e100e262a0f8f7746b78f8f87a5d"},
+ "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
+ "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
+ "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
+ "makeup_erlang": {:hex, :makeup_erlang, "1.0.3", "4252d5d4098da7415c390e847c814bad3764c94a814a0b4245176215615e1035", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "953297c02582a33411ac6208f2c6e55f0e870df7f80da724ed613f10e6706afd"},
+ "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
}
diff --git a/test/bbcode/generator_test.exs b/test/bbcode/generator_test.exs
index c6563e6..ab9ac5b 100644
--- a/test/bbcode/generator_test.exs
+++ b/test/bbcode/generator_test.exs
@@ -1,160 +1,165 @@
# SPDX-FileCopyrightText: 2019-2022 Pleroma Authors
# SPDX-License-Identifier: LGPL-3.0-only
defmodule BBCode.Generator.Test do
use ExUnit.Case
describe "simple tags" do
test "[b] tags are translated to <strong>" do
assert {:ok, "<strong>testing</strong>"} = BBCode.to_html("[b]testing[/b]")
end
test "[i] tags are translated to <em>" do
assert {:ok, "<em>testing</em>"} = BBCode.to_html("[i]testing[/i]")
end
test "[u] tags are translated to <u>" do
assert {:ok, "<u>testing</u>"} = BBCode.to_html("[u]testing[/u]")
end
test "[s] tags are translated to <del>" do
assert {:ok, "<del>testing</del>"} = BBCode.to_html("[s]testing[/s]")
end
test "[code] tags are translated to <pre>" do
assert {:ok, "<pre>testing</pre>"} = BBCode.to_html("[code]testing[/code]")
end
test "[quote] tags are translated to <blockquote>" do
assert {:ok, "<blockquote>testing</blockquote>"} = BBCode.to_html("[quote]testing[/quote]")
end
test "compounding simple tags works as expected" do
assert {:ok, "<strong><em>testing</em></strong>"} = BBCode.to_html("[b][i]testing[/i][/b]")
end
+
+ test "[ruby] tags are translated to ruby-text" do
+ assert {:ok, "<ruby>X<rp>(</rp><rt>eks</rt><rp>)</rp></ruby>"} =
+ BBCode.to_html("[ruby=eks]X[/ruby]")
+ end
end
describe "lists" do
test "[ul] lists are rendered properly" do
data = """
[ul]
[*]a
[*]b
[*]c
[/ul]
"""
expected = "<ul><li>a</li><li>b</li><li>c</li></ul>"
assert {:ok, ^expected} = BBCode.to_html(data)
end
test "[ol] lists are rendered properly" do
data = """
[ol]
[*]a
[*]b
[*]c
[/ol]
"""
expected = "<ol><li>a</li><li>b</li><li>c</li></ol>"
assert {:ok, ^expected} = BBCode.to_html(data)
end
end
describe "tables" do
test "[table] tables are rendered properly" do
data = """
[table]
[tr]
[th]header[/th]
[/tr]
[tr]
[td]cell[/td]
[/tr]
[/table]
"""
expected = "<table><tr><th>header</th></tr><tr><td>cell</td></tr></table>"
assert {:ok, ^expected} = BBCode.to_html(data)
end
end
describe "links" do
test "bare [url] links are rendered properly" do
data = """
[url]http://example.com[/url]
"""
expected = "<a href=\"http://example.com\">http://example.com</a><br>"
assert {:ok, ^expected} = BBCode.to_html(data)
end
test "named [url] links are rendered properly" do
data = """
[url=http://example.com]Example[/url]
"""
expected = "<a href=\"http://example.com\">Example</a><br>"
assert {:ok, ^expected} = BBCode.to_html(data)
end
end
describe "images" do
test "bare [img] links are rendered properly" do
data = """
[img]http://example.com/image.jpg[/img]
"""
expected = "<img src=\"http://example.com/image.jpg\"><br>"
assert {:ok, ^expected} = BBCode.to_html(data)
end
test "sized [img] links are rendered properly" do
data = """
[img=32x32]http://example.com/image.jpg[/img]
"""
expected = "<img src=\"http://example.com/image.jpg\" width=\"32\" height=\"32\"><br>"
assert {:ok, ^expected} = BBCode.to_html(data)
end
end
describe "documents" do
test "it correctly renders a complex document" do
data = """
[quote]
A multiline quote.
This is the second line.
[/quote]
[ul]
[*]a
[*]b
[*]c
[/ul]
[b]bold[/b]
[i]italic[/i]
[u]underline[/u]
[s]strikethrough[/s]
[url=http://example.com]a link[/url]
@kaniini (a mention)
"""
{:ok, output} = BBCode.to_html(data)
assert output ==
"<blockquote>A multiline quote.<br>This is the second line.<br></blockquote><ul><li>a</li><li>b</li><li>c</li></ul><strong>bold</strong><br><em>italic</em><br><u>underline</u><br><del>strikethrough</del><br><br><a href=\"http://example.com\">a link</a><br><br>@kaniini (a mention)<br>"
end
end
end

File Metadata

Mime Type
text/x-diff
Expires
Sat, Aug 8, 12:15 PM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1721742
Default Alt Text
(24 KB)

Event Timeline