Skip to content

Commit

Permalink
Add sundown to src/rt/
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Sep 24, 2013
1 parent 9705399 commit 342f829
Show file tree
Hide file tree
Showing 27 changed files with 5,472 additions and 4 deletions.
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ do
isaac linenoise sync test \
arch/i386 arch/x86_64 arch/arm arch/mips \
libuv libuv/src/ares libuv/src/eio libuv/src/ev \
jemalloc
jemalloc sundown/src sundown/html
do
make_dir $t/rt/stage$s/$i
done
Expand Down
13 changes: 12 additions & 1 deletion mk/rt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ RUNTIME_CXXS_$(1)_$(2) := \
rt/rust_android_dummy.cpp \
rt/rust_test_helpers.cpp

RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c rt/linenoise/utf8.c
RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c \
rt/linenoise/utf8.c \
rt/sundown/src/autolink.c \
rt/sundown/src/buffer.c \
rt/sundown/src/stack.c \
rt/sundown/src/markdown.c \
rt/sundown/html/houdini_href_e.c \
rt/sundown/html/houdini_html_e.c \
rt/sundown/html/html_smartypants.c \
rt/sundown/html/html.c

RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
rt/arch/$$(HOST_$(1))/ccall.S \
Expand Down Expand Up @@ -117,6 +126,8 @@ RUNTIME_DEF_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/rustrt$$(CFG_DEF_SUFFIX_$(1))
RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
-I $$(S)src/rt/arch/$$(HOST_$(1)) \
-I $$(S)src/rt/linenoise \
-I $$(S)src/rt/sundown/src \
-I $$(S)src/rt/sundown/html \
-I $$(S)src/libuv/include
RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
$$(RUNTIME_CS_$(1)_$(2):rt/%.c=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
Expand Down
7 changes: 5 additions & 2 deletions mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ ALL_CS := $(wildcard $(S)src/rt/*.cpp \
$(S)src/rt/*/*/*.cpp \
$(S)src/rustllvm/*.cpp)
ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
$(S)src/rt/linenoise/linenoise.c \
$(S)src/rt/linenoise/utf8.c \
$(wildcard $(S)src/rt/linenoise/*.c) \
$(wildcard $(S)src/rt/sundown/src/*.c) \
$(wildcard $(S)src/rt/sundown/html/*.c) \
,$(ALL_CS))
ALL_HS := $(wildcard $(S)src/rt/*.h \
$(S)src/rt/*/*.h \
Expand All @@ -241,6 +242,8 @@ ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
$(S)src/rt/msvc/inttypes.h \
$(S)src/rt/linenoise/linenoise.h \
$(S)src/rt/linenoise/utf8.h \
$(wildcard $(S)src/rt/sundown/src/*.h) \
$(wildcard $(S)src/rt/sundown/html/*.h) \
,$(ALL_HS))

# Run the tidy script in multiple parts to avoid huge 'echo' commands
Expand Down
6 changes: 6 additions & 0 deletions src/rt/rustrt.def.in
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,9 @@ rust_set_stdio_container_fd
rust_set_stdio_container_stream
rust_uv_process_pid
rust_uv_pipe_init
sdhtml_renderer
sd_markdown_new
sd_markdown_render
sd_markdown_free
bufrelease
bufnew
5 changes: 5 additions & 0 deletions src/rt/sundown/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.o
libsundown.so*
sundown
smartypants
*.exe
10 changes: 10 additions & 0 deletions src/rt/sundown/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Contributing to Sundown
=======================

Do not.

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.

The new parser will be smaller, faster, safer and most importantly, more consistent.

Please stay tuned.
83 changes: 83 additions & 0 deletions src/rt/sundown/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Makefile

# Copyright (c) 2009, Natacha Porté
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

DEPDIR=depends

# "Machine-dependant" options
#MFLAGS=-fPIC

CFLAGS=-c -g -O3 -fPIC -Wall -Werror -Wsign-compare -Isrc -Ihtml
LDFLAGS=-g -O3 -Wall -Werror
CC=gcc


SUNDOWN_SRC=\
src/markdown.o \
src/stack.o \
src/buffer.o \
src/autolink.o \
html/html.o \
html/html_smartypants.o \
html/houdini_html_e.o \
html/houdini_href_e.o

all: libsundown.so sundown smartypants html_blocks

.PHONY: all clean

# libraries

libsundown.so: libsundown.so.1
ln -f -s $^ $@

libsundown.so.1: $(SUNDOWN_SRC)
$(CC) $(LDFLAGS) -shared -Wl $^ -o $@

# executables

sundown: examples/sundown.o $(SUNDOWN_SRC)
$(CC) $(LDFLAGS) $^ -o $@

smartypants: examples/smartypants.o $(SUNDOWN_SRC)
$(CC) $(LDFLAGS) $^ -o $@

# perfect hashing
html_blocks: src/html_blocks.h

src/html_blocks.h: html_block_names.txt
gperf -N find_block_tag -H hash_block_tag -C -c -E --ignore-case $^ > $@


# housekeeping
clean:
rm -f src/*.o html/*.o examples/*.o
rm -f libsundown.so libsundown.so.1 sundown smartypants
rm -f sundown.exe smartypants.exe
rm -rf $(DEPDIR)


# dependencies

include $(wildcard $(DEPDIR)/*.d)


# generic object compilations

%.o: src/%.c examples/%.c html/%.c
@mkdir -p $(DEPDIR)
@$(CC) -MM $< > $(DEPDIR)/$*.d
$(CC) $(CFLAGS) -o $@ $<

33 changes: 33 additions & 0 deletions src/rt/sundown/Makefile.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

CFLAGS=/O2 /EHsc /I"src/" /I"examples"/ /I"html"/
CC=cl

SUNDOWN_SRC=\
src\markdown.obj \
src\stack.obj \
src\buffer.obj \
src\autolink.obj \
html\html.obj \
html\html_smartypants.obj \
html\houdini_html_e.obj \
html\houdini_href_e.obj

all: sundown.dll sundown.exe

sundown.dll: $(SUNDOWN_SRC) sundown.def
$(CC) $(SUNDOWN_SRC) sundown.def /link /DLL $(LDFLAGS) /out:$@

sundown.exe: examples\sundown.obj $(SUNDOWN_SRC)
$(CC) examples\sundown.obj $(SUNDOWN_SRC) /link $(LDFLAGS) /out:$@

# housekeeping
clean:
del $(SUNDOWN_SRC)
del sundown.dll sundown.exe
del sundown.exp sundown.lib

# generic object compilations

.c.obj:
$(CC) $(CFLAGS) /c $< /Fo$@

131 changes: 131 additions & 0 deletions src/rt/sundown/README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
Sundown
=======

`Sundown` is a Markdown parser based on the original code of the
[Upskirt library](http://fossil.instinctive.eu/libupskirt/index) by Natacha Porté.

Features
--------

* **Fully standards compliant**

`Sundown` passes out of the box the official Markdown v1.0.0 and v1.0.3
test suites, and has been extensively tested with additional corner cases
to make sure its output is as sane as possible at all times.

* **Massive extension support**

`Sundown` has optional support for several (unofficial) Markdown extensions,
such as non-strict emphasis, fenced code blocks, tables, autolinks,
strikethrough and more.

* **UTF-8 aware**

`Sundown` is fully UTF-8 aware, both when parsing the source document and when
generating the resulting (X)HTML code.

* **Tested & Ready to be used on production**

`Sundown` has been extensively security audited, and includes protection against
all possible DOS attacks (stack overflows, out of memory situations, malformed
Markdown syntax...) and against client attacks through malicious embedded HTML.

We've worked very hard to make `Sundown` never crash or run out of memory
under *any* input. `Sundown` renders all the Markdown content in GitHub and so
far hasn't crashed a single time.

* **Customizable renderers**

`Sundown` is not stuck with XHTML output: the Markdown parser of the library
is decoupled from the renderer, so it's trivial to extend the library with
custom renderers. A fully functional (X)HTML renderer is included.

* **Optimized for speed**

`Sundown` is written in C, with a special emphasis on performance. When wrapped
on a dynamic language such as Python or Ruby, it has shown to be up to 40
times faster than other native alternatives.

* **Zero-dependency**

`Sundown` is a zero-dependency library composed of 3 `.c` files and their headers.
No dependencies, no bullshit. Only standard C99 that builds everywhere.

Credits
-------

`Sundown` is based on the original Upskirt parser by Natacha Porté, with many additions
by Vicent Marti (@vmg) and contributions from the following authors:

Ben Noordhuis, Bruno Michel, Joseph Koshy, Krzysztof Kowalczyk, Samuel Bronson,
Shuhei Tanuma

Bindings
--------

`Sundown` is available from other programming languages thanks to these bindings developed
by our awesome contributors.

- [Redcarpet](https://github.com/vmg/redcarpet) (Ruby)
- [RobotSkirt](https://github.com/benmills/robotskirt) (Node.js)
- [Misaka](https://github.com/FSX/misaka) (Python)
- [ffi-sundown](https://github.com/postmodern/ffi-sundown) (Ruby FFI)
- [Sundown HS](https://github.com/bitonic/sundown) (Haskell)
- [Goskirt](https://github.com/madari/goskirt) (Go)
- [Upskirt.go](https://github.com/buu700/upskirt.go) (Go)
- [MoonShine](https://github.com/brandonc/moonshine) (.NET)
- [PHP-Sundown](https://github.com/chobie/php-sundown) (PHP)
- [Sundown.net](https://github.com/txdv/sundown.net) (.NET)

Help us
-------

`Sundown` is all about security. If you find a (potential) security vulnerability in the
library, or a way to make it crash through malicious input, please report it to us,
either directly via email or by opening an Issue on GitHub, and help make the web safer
for everybody.

Unicode character handling
--------------------------

Given that the Markdown spec makes no provision for Unicode character handling, `Sundown`
takes a conservative approach towards deciding which extended characters trigger Markdown
features:

* Punctuation characters outside of the U+007F codepoint are not handled as punctuation.
They are considered as normal, in-word characters for word-boundary checks.

* Whitespace characters outside of the U+007F codepoint are not considered as
whitespace. They are considered as normal, in-word characters for word-boundary checks.

Install
-------

There is nothing to install. `Sundown` is composed of 3 `.c` files (`markdown.c`,
`buffer.c` and `array.c`), so just throw them in your project. Zero-dependency means
zero-dependency. You might want to include `render/html.c` if you want to use the
included XHTML renderer, or write your own renderer. Either way, it's all fun and joy.

If you are hardcore, you can use the included `Makefile` to build `Sundown` into a dynamic
library, or to build the sample `sundown` executable, which is just a commandline
Markdown to XHTML parser. (If gcc gives you grief about `-fPIC`, e.g. with MinGW, try
`make MFLAGS=` instead of just `make`.)

License
-------

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

<!-- Local Variables: -->
<!-- fill-column: 89 -->
<!-- End: -->
Loading

0 comments on commit 342f829

Please sign in to comment.