Skip to content

Commit 342f829

Browse files
committed
Add sundown to src/rt/
This also starts compiling it in the same manner as linenoise, it's just bundled with librustrt directly, and we export just a few symbols out of it.
1 parent 9705399 commit 342f829

27 files changed

+5472
-4
lines changed

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ do
684684
isaac linenoise sync test \
685685
arch/i386 arch/x86_64 arch/arm arch/mips \
686686
libuv libuv/src/ares libuv/src/eio libuv/src/ev \
687-
jemalloc
687+
jemalloc sundown/src sundown/html
688688
do
689689
make_dir $t/rt/stage$s/$i
690690
done

mk/rt.mk

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,16 @@ RUNTIME_CXXS_$(1)_$(2) := \
8282
rt/rust_android_dummy.cpp \
8383
rt/rust_test_helpers.cpp
8484

85-
RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
85+
RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c \
86+
rt/linenoise/utf8.c \
87+
rt/sundown/src/autolink.c \
88+
rt/sundown/src/buffer.c \
89+
rt/sundown/src/stack.c \
90+
rt/sundown/src/markdown.c \
91+
rt/sundown/html/houdini_href_e.c \
92+
rt/sundown/html/houdini_html_e.c \
93+
rt/sundown/html/html_smartypants.c \
94+
rt/sundown/html/html.c
8695

8796
RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
8897
rt/arch/$$(HOST_$(1))/ccall.S \
@@ -117,6 +126,8 @@ RUNTIME_DEF_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/rustrt$$(CFG_DEF_SUFFIX_$(1))
117126
RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
118127
-I $$(S)src/rt/arch/$$(HOST_$(1)) \
119128
-I $$(S)src/rt/linenoise \
129+
-I $$(S)src/rt/sundown/src \
130+
-I $$(S)src/rt/sundown/html \
120131
-I $$(S)src/libuv/include
121132
RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
122133
$$(RUNTIME_CS_$(1)_$(2):rt/%.c=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \

mk/tests.mk

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ ALL_CS := $(wildcard $(S)src/rt/*.cpp \
227227
$(S)src/rt/*/*/*.cpp \
228228
$(S)src/rustllvm/*.cpp)
229229
ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
230-
$(S)src/rt/linenoise/linenoise.c \
231-
$(S)src/rt/linenoise/utf8.c \
230+
$(wildcard $(S)src/rt/linenoise/*.c) \
231+
$(wildcard $(S)src/rt/sundown/src/*.c) \
232+
$(wildcard $(S)src/rt/sundown/html/*.c) \
232233
,$(ALL_CS))
233234
ALL_HS := $(wildcard $(S)src/rt/*.h \
234235
$(S)src/rt/*/*.h \
@@ -241,6 +242,8 @@ ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
241242
$(S)src/rt/msvc/inttypes.h \
242243
$(S)src/rt/linenoise/linenoise.h \
243244
$(S)src/rt/linenoise/utf8.h \
245+
$(wildcard $(S)src/rt/sundown/src/*.h) \
246+
$(wildcard $(S)src/rt/sundown/html/*.h) \
244247
,$(ALL_HS))
245248

246249
# Run the tidy script in multiple parts to avoid huge 'echo' commands

src/rt/rustrt.def.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,9 @@ rust_set_stdio_container_fd
200200
rust_set_stdio_container_stream
201201
rust_uv_process_pid
202202
rust_uv_pipe_init
203+
sdhtml_renderer
204+
sd_markdown_new
205+
sd_markdown_render
206+
sd_markdown_free
207+
bufrelease
208+
bufnew

src/rt/sundown/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.o
2+
libsundown.so*
3+
sundown
4+
smartypants
5+
*.exe

src/rt/sundown/CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Contributing to Sundown
2+
=======================
3+
4+
Do not.
5+
6+
Unfortunately, Sundown is currently frozen as we're working with the Reddit, StackOverflow and Meteor developers to design a formal Markdown standard and parser that will supersede Sundown in all these websites (and in GitHub, of course). Our goal is to deprecate Sundown altogether before the end of the year.
7+
8+
The new parser will be smaller, faster, safer and most importantly, more consistent.
9+
10+
Please stay tuned.

src/rt/sundown/Makefile

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Makefile
2+
3+
# Copyright (c) 2009, Natacha Porté
4+
#
5+
# Permission to use, copy, modify, and distribute this software for any
6+
# purpose with or without fee is hereby granted, provided that the above
7+
# copyright notice and this permission notice appear in all copies.
8+
#
9+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
17+
DEPDIR=depends
18+
19+
# "Machine-dependant" options
20+
#MFLAGS=-fPIC
21+
22+
CFLAGS=-c -g -O3 -fPIC -Wall -Werror -Wsign-compare -Isrc -Ihtml
23+
LDFLAGS=-g -O3 -Wall -Werror
24+
CC=gcc
25+
26+
27+
SUNDOWN_SRC=\
28+
src/markdown.o \
29+
src/stack.o \
30+
src/buffer.o \
31+
src/autolink.o \
32+
html/html.o \
33+
html/html_smartypants.o \
34+
html/houdini_html_e.o \
35+
html/houdini_href_e.o
36+
37+
all: libsundown.so sundown smartypants html_blocks
38+
39+
.PHONY: all clean
40+
41+
# libraries
42+
43+
libsundown.so: libsundown.so.1
44+
ln -f -s $^ $@
45+
46+
libsundown.so.1: $(SUNDOWN_SRC)
47+
$(CC) $(LDFLAGS) -shared -Wl $^ -o $@
48+
49+
# executables
50+
51+
sundown: examples/sundown.o $(SUNDOWN_SRC)
52+
$(CC) $(LDFLAGS) $^ -o $@
53+
54+
smartypants: examples/smartypants.o $(SUNDOWN_SRC)
55+
$(CC) $(LDFLAGS) $^ -o $@
56+
57+
# perfect hashing
58+
html_blocks: src/html_blocks.h
59+
60+
src/html_blocks.h: html_block_names.txt
61+
gperf -N find_block_tag -H hash_block_tag -C -c -E --ignore-case $^ > $@
62+
63+
64+
# housekeeping
65+
clean:
66+
rm -f src/*.o html/*.o examples/*.o
67+
rm -f libsundown.so libsundown.so.1 sundown smartypants
68+
rm -f sundown.exe smartypants.exe
69+
rm -rf $(DEPDIR)
70+
71+
72+
# dependencies
73+
74+
include $(wildcard $(DEPDIR)/*.d)
75+
76+
77+
# generic object compilations
78+
79+
%.o: src/%.c examples/%.c html/%.c
80+
@mkdir -p $(DEPDIR)
81+
@$(CC) -MM $< > $(DEPDIR)/$*.d
82+
$(CC) $(CFLAGS) -o $@ $<
83+

src/rt/sundown/Makefile.win

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
CFLAGS=/O2 /EHsc /I"src/" /I"examples"/ /I"html"/
3+
CC=cl
4+
5+
SUNDOWN_SRC=\
6+
src\markdown.obj \
7+
src\stack.obj \
8+
src\buffer.obj \
9+
src\autolink.obj \
10+
html\html.obj \
11+
html\html_smartypants.obj \
12+
html\houdini_html_e.obj \
13+
html\houdini_href_e.obj
14+
15+
all: sundown.dll sundown.exe
16+
17+
sundown.dll: $(SUNDOWN_SRC) sundown.def
18+
$(CC) $(SUNDOWN_SRC) sundown.def /link /DLL $(LDFLAGS) /out:$@
19+
20+
sundown.exe: examples\sundown.obj $(SUNDOWN_SRC)
21+
$(CC) examples\sundown.obj $(SUNDOWN_SRC) /link $(LDFLAGS) /out:$@
22+
23+
# housekeeping
24+
clean:
25+
del $(SUNDOWN_SRC)
26+
del sundown.dll sundown.exe
27+
del sundown.exp sundown.lib
28+
29+
# generic object compilations
30+
31+
.c.obj:
32+
$(CC) $(CFLAGS) /c $< /Fo$@
33+

src/rt/sundown/README.markdown

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
Sundown
2+
=======
3+
4+
`Sundown` is a Markdown parser based on the original code of the
5+
[Upskirt library](http://fossil.instinctive.eu/libupskirt/index) by Natacha Porté.
6+
7+
Features
8+
--------
9+
10+
* **Fully standards compliant**
11+
12+
`Sundown` passes out of the box the official Markdown v1.0.0 and v1.0.3
13+
test suites, and has been extensively tested with additional corner cases
14+
to make sure its output is as sane as possible at all times.
15+
16+
* **Massive extension support**
17+
18+
`Sundown` has optional support for several (unofficial) Markdown extensions,
19+
such as non-strict emphasis, fenced code blocks, tables, autolinks,
20+
strikethrough and more.
21+
22+
* **UTF-8 aware**
23+
24+
`Sundown` is fully UTF-8 aware, both when parsing the source document and when
25+
generating the resulting (X)HTML code.
26+
27+
* **Tested & Ready to be used on production**
28+
29+
`Sundown` has been extensively security audited, and includes protection against
30+
all possible DOS attacks (stack overflows, out of memory situations, malformed
31+
Markdown syntax...) and against client attacks through malicious embedded HTML.
32+
33+
We've worked very hard to make `Sundown` never crash or run out of memory
34+
under *any* input. `Sundown` renders all the Markdown content in GitHub and so
35+
far hasn't crashed a single time.
36+
37+
* **Customizable renderers**
38+
39+
`Sundown` is not stuck with XHTML output: the Markdown parser of the library
40+
is decoupled from the renderer, so it's trivial to extend the library with
41+
custom renderers. A fully functional (X)HTML renderer is included.
42+
43+
* **Optimized for speed**
44+
45+
`Sundown` is written in C, with a special emphasis on performance. When wrapped
46+
on a dynamic language such as Python or Ruby, it has shown to be up to 40
47+
times faster than other native alternatives.
48+
49+
* **Zero-dependency**
50+
51+
`Sundown` is a zero-dependency library composed of 3 `.c` files and their headers.
52+
No dependencies, no bullshit. Only standard C99 that builds everywhere.
53+
54+
Credits
55+
-------
56+
57+
`Sundown` is based on the original Upskirt parser by Natacha Porté, with many additions
58+
by Vicent Marti (@vmg) and contributions from the following authors:
59+
60+
Ben Noordhuis, Bruno Michel, Joseph Koshy, Krzysztof Kowalczyk, Samuel Bronson,
61+
Shuhei Tanuma
62+
63+
Bindings
64+
--------
65+
66+
`Sundown` is available from other programming languages thanks to these bindings developed
67+
by our awesome contributors.
68+
69+
- [Redcarpet](https://github.com/vmg/redcarpet) (Ruby)
70+
- [RobotSkirt](https://github.com/benmills/robotskirt) (Node.js)
71+
- [Misaka](https://github.com/FSX/misaka) (Python)
72+
- [ffi-sundown](https://github.com/postmodern/ffi-sundown) (Ruby FFI)
73+
- [Sundown HS](https://github.com/bitonic/sundown) (Haskell)
74+
- [Goskirt](https://github.com/madari/goskirt) (Go)
75+
- [Upskirt.go](https://github.com/buu700/upskirt.go) (Go)
76+
- [MoonShine](https://github.com/brandonc/moonshine) (.NET)
77+
- [PHP-Sundown](https://github.com/chobie/php-sundown) (PHP)
78+
- [Sundown.net](https://github.com/txdv/sundown.net) (.NET)
79+
80+
Help us
81+
-------
82+
83+
`Sundown` is all about security. If you find a (potential) security vulnerability in the
84+
library, or a way to make it crash through malicious input, please report it to us,
85+
either directly via email or by opening an Issue on GitHub, and help make the web safer
86+
for everybody.
87+
88+
Unicode character handling
89+
--------------------------
90+
91+
Given that the Markdown spec makes no provision for Unicode character handling, `Sundown`
92+
takes a conservative approach towards deciding which extended characters trigger Markdown
93+
features:
94+
95+
* Punctuation characters outside of the U+007F codepoint are not handled as punctuation.
96+
They are considered as normal, in-word characters for word-boundary checks.
97+
98+
* Whitespace characters outside of the U+007F codepoint are not considered as
99+
whitespace. They are considered as normal, in-word characters for word-boundary checks.
100+
101+
Install
102+
-------
103+
104+
There is nothing to install. `Sundown` is composed of 3 `.c` files (`markdown.c`,
105+
`buffer.c` and `array.c`), so just throw them in your project. Zero-dependency means
106+
zero-dependency. You might want to include `render/html.c` if you want to use the
107+
included XHTML renderer, or write your own renderer. Either way, it's all fun and joy.
108+
109+
If you are hardcore, you can use the included `Makefile` to build `Sundown` into a dynamic
110+
library, or to build the sample `sundown` executable, which is just a commandline
111+
Markdown to XHTML parser. (If gcc gives you grief about `-fPIC`, e.g. with MinGW, try
112+
`make MFLAGS=` instead of just `make`.)
113+
114+
License
115+
-------
116+
117+
Permission to use, copy, modify, and distribute this software for any
118+
purpose with or without fee is hereby granted, provided that the above
119+
copyright notice and this permission notice appear in all copies.
120+
121+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
122+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
123+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
124+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
125+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
126+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
127+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
128+
129+
<!-- Local Variables: -->
130+
<!-- fill-column: 89 -->
131+
<!-- End: -->

0 commit comments

Comments
 (0)