Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
FastHTML
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pleroma
Elixir libraries
FastHTML
Commits
a2a685a5
Commit
a2a685a5
authored
Nov 06, 2019
by
kaniini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rebrand Myhtmlex module to :fast_html part 1
parent
564532c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
41 deletions
+41
-41
Makefile
Makefile
+17
-17
lib/fast_html.ex
lib/fast_html.ex
+10
-10
test/fast_html_test.exs
test/fast_html_test.exs
+14
-14
No files found.
Makefile
View file @
a2a685a5
MIX
=
mix
MYHTML
EX
_CFLAGS
=
-g
-O2
-std
=
c99
-pedantic
-Wcomment
-Wextra
-Wno-old-style-declaration
-Wall
MYHTML
_WORKER
_CFLAGS
=
-g
-O2
-std
=
c99
-pedantic
-Wcomment
-Wextra
-Wno-old-style-declaration
-Wall
# we need to compile position independent code
MYHTML
EX
_CFLAGS
+=
-fpic
-DPIC
MYHTML
_WORKER
_CFLAGS
+=
-fpic
-DPIC
# For some reason __erl_errno is undefined unless _REENTRANT is defined
MYHTML
EX
_CFLAGS
+=
-D_REENTRANT
MYHTML
_WORKER
_CFLAGS
+=
-D_REENTRANT
# myhtmlex is using stpcpy, as defined in gnu string.h
# MYHTML
EX
_CFLAGS += -D_GNU_SOURCE
# MYHTML
_WORKER
_CFLAGS += -D_GNU_SOURCE
# base on the same posix c source as myhtml
# MYHTML
EX
_CFLAGS += -D_POSIX_C_SOURCE=199309
# MYHTML
_WORKER
_CFLAGS += -D_POSIX_C_SOURCE=199309
# turn warnings into errors
# MYHTML
EX
_CFLAGS += -Werror
# MYHTML
_WORKER
_CFLAGS += -Werror
# ignore unused variables
# MYHTML
EX
_CFLAGS += -Wno-unused-variable
# MYHTML
_WORKER
_CFLAGS += -Wno-unused-variable
# ignore unused parameter warnings
MYHTML
EX
_CFLAGS
+=
-Wno-unused-parameter
MYHTML
_WORKER
_CFLAGS
+=
-Wno-unused-parameter
# set erlang include path
ERLANG_PATH
=
$(
shell
erl
-eval
'io:format("~s", [lists:concat([code:root_dir(
)
, "/erts-", erlang:system_info(version
)
]
)
]
)
'
-s
init stop
-noshell
)
MYHTML
EX
_CFLAGS
+=
-I
$(ERLANG_PATH)
/include
MYHTML
_WORKER
_CFLAGS
+=
-I
$(ERLANG_PATH)
/include
# expecting myhtml as a submodule in c_src/
# that way we can pin a version and package the whole thing in hex
# hex does not allow for non-app related dependencies.
MYHTML_PATH
=
c_src/myhtml
MYHTML_STATIC
=
$(MYHTML_PATH)
/lib/libmyhtml_static.a
MYHTML
EX
_CFLAGS
+=
-I
$(MYHTML_PATH)
/include
MYHTML
_WORKER
_CFLAGS
+=
-I
$(MYHTML_PATH)
/include
# avoid undefined reference errors to phtread_mutex_trylock
MYHTML
EX
_CFLAGS
+=
-lpthread
MYHTML
_WORKER
_CFLAGS
+=
-lpthread
# that would be used for a dynamically linked build
# MYHTML
EX
_CFLAGS += -L$(MYHTML_PATH)/lib
# MYHTML
_WORKER
_CFLAGS += -L$(MYHTML_PATH)/lib
MYHTML
EX
_LDFLAGS
=
-shared
MYHTML
_WORKER
_LDFLAGS
=
-shared
# C-Node
ERL_INTERFACE
=
$(
wildcard
$(ERLANG_PATH)
/../lib/erl_interface-
*
)
CNODE_CFLAGS
=
$(MYHTML
EX
_CFLAGS)
CNODE_CFLAGS
=
$(MYHTML
_WORKER
_CFLAGS)
CNODE_CFLAGS
+=
-L
$(ERL_INTERFACE)
/lib
CNODE_CFLAGS
+=
-I
$(ERL_INTERFACE)
/include
...
...
@@ -55,12 +55,12 @@ BUILD_TESTS := $(patsubst %.dockerfile, %.dockerfile.PHONY, $(wildcard ./build-t
# platform specific environment
UNAME
=
$(
shell
uname
-s
)
ifeq
($(UNAME_S),Darwin)
MYHTML
EX
_LDFLAGS
+=
-dynamiclib
-undefined
dynamic_lookup
MYHTML
_WORKER
_LDFLAGS
+=
-dynamiclib
-undefined
dynamic_lookup
else
# myhtmlex is using stpcpy, as defined in gnu string.h
MYHTML
EX
_CFLAGS
+=
-D_GNU_SOURCE
MYHTML
_WORKER
_CFLAGS
+=
-D_GNU_SOURCE
# base on the same posix c source as myhtml
# MYHTML
EX
_CFLAGS += -D_POSIX_C_SOURCE=199309
# MYHTML
_WORKER
_CFLAGS += -D_POSIX_C_SOURCE=199309
endif
.PHONY
:
all
...
...
lib/
myhtmlex
.ex
→
lib/
fast_html
.ex
View file @
a2a685a5
defmodule
Myhtmlex
do
defmodule
:fast_html
do
@moduledoc
"""
A module to decode html into a tree structure.
...
...
@@ -7,7 +7,7 @@ defmodule Myhtmlex do
## Example
iex>
Myhtmlex
.decode("<h1>Hello world</h1>")
iex>
:fast_html
.decode("<h1>Hello world</h1>")
{"html", [], [{"head", [], []}, {"body", [], [{"h1", [], ["Hello world"]}]}]}
Benchmark results (removed Nif calling mode) on various file sizes on a 2,5Ghz Core i7:
...
...
@@ -46,18 +46,18 @@ defmodule Myhtmlex do
## Examples
iex>
Myhtmlex
.decode("<h1>Hello world</h1>")
iex>
:fast_html
.decode("<h1>Hello world</h1>")
{"html", [], [{"head", [], []}, {"body", [], [{"h1", [], ["Hello world"]}]}]}
iex>
Myhtmlex
.decode("<span class='hello'>Hi there</span>")
iex>
:fast_html
.decode("<span class='hello'>Hi there</span>")
{"html", [],
[{"head", [], []},
{"body", [], [{"span", [{"class", "hello"}], ["Hi there"]}]}]}
iex>
Myhtmlex
.decode("<body><!-- a comment --!></body>")
iex>
:fast_html
.decode("<body><!-- a comment --!></body>")
{"html", [], [{"head", [], []}, {"body", [], [comment: " a comment "]}]}
iex>
Myhtmlex
.decode("<br>")
iex>
:fast_html
.decode("<br>")
{"html", [], [{"head", [], []}, {"body", [], [{"br", [], []}]}]}
"""
@spec
decode
(
String
.
t
())
::
tree
()
...
...
@@ -78,17 +78,17 @@ defmodule Myhtmlex do
## Examples
iex>
Myhtmlex
.decode("<h1>Hello world</h1>", format: [:html_atoms])
iex>
:fast_html
.decode("<h1>Hello world</h1>", format: [:html_atoms])
{:html, [], [{:head, [], []}, {:body, [], [{:h1, [], ["Hello world"]}]}]}
iex>
Myhtmlex
.decode("<br>", format: [:nil_self_closing])
iex>
:fast_html
.decode("<br>", format: [:nil_self_closing])
{"html", [], [{"head", [], []}, {"body", [], [{"br", [], nil}]}]}
iex>
Myhtmlex
.decode("<body><!-- a comment --!></body>", format: [:comment_tuple3])
iex>
:fast_html
.decode("<body><!-- a comment --!></body>", format: [:comment_tuple3])
{"html", [], [{"head", [], []}, {"body", [], [{:comment, [], " a comment "}]}]}
iex> html = "<body><!-- a comment --!><unknown /></body>"
iex>
Myhtmlex
.decode(html, format: [:html_atoms, :nil_self_closing, :comment_tuple3])
iex>
:fast_html
.decode(html, format: [:html_atoms, :nil_self_closing, :comment_tuple3])
{:html, [],
[{:head, [], []},
{:body, [], [{:comment, [], " a comment "}, {"unknown", [], nil}]}]}
...
...
test/
myhtmlex.safe
_test.exs
→
test/
fast_html
_test.exs
View file @
a2a685a5
defmodule
Myhtmlex
.
SafeT
est
do
defmodule
:fast_html_t
est
do
use
ExUnit
.
Case
doctest
Myhtmlex
doctest
:fast_html
test
"doesn't segfault when <!----> is encountered"
do
assert
{
"html"
,
_attrs
,
_children
}
=
Myhtmlex
.
decode
(
"<div> <!----> </div>"
)
assert
{
"html"
,
_attrs
,
_children
}
=
:fast_html
.
decode
(
"<div> <!----> </div>"
)
end
test
"builds a tree, formatted like mochiweb by default"
do
...
...
@@ -14,7 +14,7 @@ defmodule Myhtmlex.SafeTest do
[
{
"br"
,
[],
[]}
]}
]}
=
Myhtmlex
.
decode
(
"<br>"
)
]}
=
:fast_html
.
decode
(
"<br>"
)
end
test
"builds a tree, html tags as atoms"
do
...
...
@@ -25,7 +25,7 @@ defmodule Myhtmlex.SafeTest do
[
{
:br
,
[],
[]}
]}
]}
=
Myhtmlex
.
decode
(
"<br>"
,
format:
[
:html_atoms
])
]}
=
:fast_html
.
decode
(
"<br>"
,
format:
[
:html_atoms
])
end
test
"builds a tree, nil self closing"
do
...
...
@@ -37,7 +37,7 @@ defmodule Myhtmlex.SafeTest do
{
"br"
,
[],
nil
},
{
"esi:include"
,
[],
nil
}
]}
]}
=
Myhtmlex
.
decode
(
"<br><esi:include />"
,
format:
[
:nil_self_closing
])
]}
=
:fast_html
.
decode
(
"<br><esi:include />"
,
format:
[
:nil_self_closing
])
end
test
"builds a tree, multiple format options"
do
...
...
@@ -48,7 +48,7 @@ defmodule Myhtmlex.SafeTest do
[
{
:br
,
[],
nil
}
]}
]}
=
Myhtmlex
.
decode
(
"<br>"
,
format:
[
:html_atoms
,
:nil_self_closing
])
]}
=
:fast_html
.
decode
(
"<br>"
,
format:
[
:html_atoms
,
:nil_self_closing
])
end
test
"attributes"
do
...
...
@@ -60,7 +60,7 @@ defmodule Myhtmlex.SafeTest do
{
:span
,
[{
"id"
,
"test"
},
{
"class"
,
"foo garble"
}],
[]}
]}
]}
=
Myhtmlex
.
decode
(
~s'<span id="test" class="foo garble"></span>'
,
:fast_html
.
decode
(
~s'<span id="test" class="foo garble"></span>'
,
format:
[
:html_atoms
]
)
end
...
...
@@ -74,7 +74,7 @@ defmodule Myhtmlex.SafeTest do
{
:button
,
[{
"disabled"
,
"disabled"
},
{
"class"
,
"foo garble"
}],
[]}
]}
]}
=
Myhtmlex
.
decode
(
~s'<button disabled class="foo garble"></span>'
,
:fast_html
.
decode
(
~s'<button disabled class="foo garble"></span>'
,
format:
[
:html_atoms
]
)
end
...
...
@@ -87,7 +87,7 @@ defmodule Myhtmlex.SafeTest do
[
"text node"
]}
]}
=
Myhtmlex
.
decode
(
~s'<body>text node</body>'
,
format:
[
:html_atoms
])
]}
=
:fast_html
.
decode
(
~s'<body>text node</body>'
,
format:
[
:html_atoms
])
end
test
"broken input"
do
...
...
@@ -98,7 +98,7 @@ defmodule Myhtmlex.SafeTest do
[
{
:a
,
[{
"<"
,
"<"
}],
[
" asdf"
]}
]}
]}
=
Myhtmlex
.
decode
(
~s'<a <> asdf'
,
format:
[
:html_atoms
])
]}
=
:fast_html
.
decode
(
~s'<a <> asdf'
,
format:
[
:html_atoms
])
end
test
"namespaced tags"
do
...
...
@@ -113,7 +113,7 @@ defmodule Myhtmlex.SafeTest do
{
"svg:a"
,
[],
[]}
]}
]}
]}
=
Myhtmlex
.
decode
(
~s'<svg><path></path><a></a></svg>'
,
format:
[
:html_atoms
])
]}
=
:fast_html
.
decode
(
~s'<svg><path></path><a></a></svg>'
,
format:
[
:html_atoms
])
end
test
"custom namespaced tags"
do
...
...
@@ -124,7 +124,7 @@ defmodule Myhtmlex.SafeTest do
[
{
"esi:include"
,
[],
nil
}
]}
]}
=
Myhtmlex
.
decode
(
~s'<esi:include />'
,
format:
[
:html_atoms
,
:nil_self_closing
])
]}
=
:fast_html
.
decode
(
~s'<esi:include />'
,
format:
[
:html_atoms
,
:nil_self_closing
])
end
test
"html comments"
do
...
...
@@ -135,6 +135,6 @@ defmodule Myhtmlex.SafeTest do
[
comment:
" a comment "
]}
]}
=
Myhtmlex
.
decode
(
~s'<body><!-- a comment --></body>'
,
format:
[
:html_atoms
])
]}
=
:fast_html
.
decode
(
~s'<body><!-- a comment --></body>'
,
format:
[
:html_atoms
])
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment