Commit Graph

111 Commits

Author SHA1 Message Date
Nick Wellnhofer
9c8e834136 Add -Wstrict-prototypes and fix offending functions 2022-01-24 09:19:18 -08:00
kyle
affa616c13 Add test for inline backtick parse 2021-11-10 08:54:41 -08:00
John MacFarlane
0d408e6cbf Expand tabs to spaces in source code.
Sources were not consistently using spaces.
2021-07-17 15:35:23 -07:00
Saleem Abdulrasool
023d887d9f build: allow building with CMake[<3.3]
The `COMPILE_LANGUAGE` generator expression was introduced in CMake 3.3.
Debian Jessie has an older CMake version bundled, which prevents
building on that platform without manually building CMake.  This
uses a more error-prone mechanism of requiring the commonmark developer
to explicitly invoke `cmark_add_compile_options` on the target to ensure
that the flags are propagated for the targets without using the
generator expression.  Adding the options unconditionally prevents using
CMark in a build with a non-C programming language.

Fixes: #384
2021-07-08 22:04:56 -07:00
Nick Wellnhofer
2994011ce1 Replace invalid characters in XML output
Control characters, U+FFFE and U+FFFF aren't allowed in XML 1.0, so
replace them with U+FFFD (replacement character). This doesn't solve
the problem how to roundtrip these characters, but at least we don't
produce invalid XML. See #365.
2021-03-18 16:02:48 -07:00
Reinhold Gschweicher
c8d5be9833 Generate and install cmake-config file
Add full cmake support. The project can either be used with
`add_subdirectory` or be installed into the system (or some other
directory) and be found with `find_package(cmark)`. In both cases the
cmake target `cmark::cmark` and/or `cmark::cmark_static` is all that
is needed to be linked.

Previously the cmarkConfig.cmake file was generated, but not installed.
As additional bonus of generation by cmake we get a generated
`cmake-config-version.cmake` file for `find_package()` to search for
the same major version.

The generated config file is position independent, allowing the
installed directory to be copied or moved and still work.

The following four files are generated and installed:
- lib/cmake/cmark/cmark-config.cmake
- lib/cmake/cmark/cmark-config-version.cmake
- lib/cmake/cmark/cmark-targets.cmake
- lib/cmake/cmark/cmark-targets-release.cmake
2020-12-03 10:26:21 -08:00
John MacFarlane
fdbdbf7ecc Add cmark_get_default_mem_allocator().
API change: This adds a new exported function in cmark.h.

Closes #330.
2020-02-09 09:03:16 -08:00
Nick Wellnhofer
b0a4cfa36e Use C string instead of chunk for literal text
Use zero-terminated C strings and a separate length field instead of
cmark_chunks. Literal inline text will now be copied from the parent
block's content buffer, slowing the benchmark down by 10-15%.

The node struct never references memory of other nodes now, fixing #309.
Node accessors don't have to check for delayed creation of C strings,
so parsing and iterating all literals using the public API should
actually be faster than before.
2020-01-23 08:25:54 -08:00
Nick Wellnhofer
b237924585 Use C string instead of chunk for link URL and title
Use zero-terminated C strings instead of cmark_chunks without storing
the length. This introduces a few additional strlen computations,
but overhead should be low.

Allows to reduce size of struct cmark_node later.
2020-01-23 08:25:54 -08:00
Saleem Abdulrasool
b6c73d8b5c build: use target properties for include paths
This configures the target to setup the include paths publicly for the
library targets in the build interface.  This enables uses of the
targets in the build tree without having to specify the include
directories.  This is particularly useful for use in the export targets,
but also simplifies the rules for the API tests.  The install interface
does not need the include directories as `cmark.h` is installed into
`include` which is a default include path.
2020-01-02 22:58:05 -07:00
Saleem Abdulrasool
b6ffaca93e build: cleanup CMake (#319)
* build: inline a variable

* build: use `LINKER_LANGUAGE` property for C++ runtime

Rather than explicitly name the C++ runtime, use the `LINKER_LANGUAGE`
property to use the driver to spell the C++ runtime appropriately.

* build: use CMake to control C standard

Rather than use compiler specific flags to control the language
standard, indicate to CMake the desired standard.

* build: use the correct variable

These flags are being applied to the *C* compiler, check the C compiler,
not the C++ compiler.

* build: loosen the compiler check

This loosens the compiler identifier check to enable matching AppleClang
which is the identifier for the Xcode compiler.

* build: hoist shared flags to top-level CMakeLists

This hoists the common shared flags handling to the top-level CMakeLists
from sub-layers.  This prevents the duplication of the handling.

* build: remove duplicated flags

This is unnecessary, `/TP` is forced on all MSVC builds, no need to
duplicate the flag for older versions.

* build: loosen C compiler identifier check

Loosen the check to a match rather than equality check, this allows it
to match AppleClang which is the identifier for the Apple vended clang
compiler part of Xcode.

* build: use `add_compile_options`

Use `add_compile_options` rather than modify `CMAKE_C_FLAGS`.  The
latter is meant to be only modified by the user, not the package
developer.

* build: hoist sanitizer flags to global state

This moves the CMAKE_C_FLAGS handling to the top-level and uses
`add_compile_options` rather than modifying the user controlled flags.

* build: hoist `-fvisibilty` flags to top-level

These are global settings, hoist them to the top level.

* build: hoist the debug flag handling

Use a generator expression and hoist the flag handling for the debug
build.

* build: hoist the profile flag handling

This is a global flag, hoist it to the top level and use
`add_compile_options` rather than modify the user controlled flags.

* build: remove incorrect variable handling

This seemed to be attempting to set the linker not the linker flags for
the profile configuration.  This variable is not used, do not set it.

* build: remove unused CMake includes
2019-12-22 10:21:35 -08:00
John MacFarlane
cb1cd888cc Fix entity parser (and api test) to respect length limit on numeric entities. 2019-11-11 12:52:35 -08:00
John MacFarlane
325a1471d2 Make rendering safe by default.
Removes CMARK_OPT_SAFE from options.

Adds CMARK_OPT_UNSAFE, with the opposite meaning.
The new default behavior is to suppress raw HTML and
potentially dangerous links.  The CMARK_OPT_UNSAFE
option has to be set explicitly to prevent this.

--------------------------------------------------------
NOTE: This change will require modifications in
bindings for cmark and in most libraries and programs
that use cmark.
--------------------------------------------------------

Closes #239, #273.

Borrows heavily from @kivikakk's patch in github/cmark-gfm#123.
2019-03-17 22:43:38 -07:00
Ashe Connor
cfba1fc382
expand tests 2018-11-13 11:06:47 +11:00
Ashe Connor
462cab4839
add failing test 2018-11-12 16:09:46 +11:00
Nguyễn Thái Ngọc Duy
55afc6fd49 Add xml:space="preserve" in XML output when appropriate
With current HTML escaping, sometimes we may produce an XML tag like

    <code_block>  </code_block>

Many XML parsers consider these spaces insignificant and strip them
out but we need this. There's actually a test case like this in
spec.txt (search "A code block can have all empty lines as its
content:") and without proper hinting, an external xml->html converter
will fail the spec.

XML standard covers this case. If xml:space is "preserve", then
whitespaces are significant and should be kept. Add this hint for
text, code, code_block, html_inline and html_block tags.
2018-07-07 19:30:34 +02:00
Nick Wellnhofer
772c4cbde5 Also run API tests with CMARK_SHARED=OFF 2017-11-18 16:16:01 +01:00
Yuki Izumi
e22d1b42ce
Fix inlines spanning newlines, text in non-para 2017-08-10 13:29:40 +10:00
Yuki Izumi
919cdb2c58
Add sourcepos info for inlines 2017-08-09 15:56:21 +10:00
John MacFarlane
0b1886ca44 Fixed cmark_node_get_list_start to return 0 for bullet lists...
as documented!

Closes #202.
2017-06-02 16:23:25 +02:00
John MacFarlane
60b6962db0 Revert "Change types for source map offsets (#174)"
This reverts commit 4fbe344df4.
2017-01-03 22:08:38 -08:00
Nick Wellnhofer
4fbe344df4 Change types for source map offsets (#174)
* Improve strbuf guarantees

Introduce BUFSIZE_MAX macro and make sure that the strbuf implementation
can handle strings up to this size.

* Abort early if document size exceeds internal limit

* Change types for source map offsets

Switch to size_t for the public API, making the public headers
C89-compatible again.

Switch to bufsize_t internally, reducing memory usage and improving
performance on 32-bit platforms.

* Make parser return NULL on internal index overflow

Make S_parser_feed set an error and ignore subsequent chunks if the
total input document size exceeds an internal limit. Make
cmark_parser_finish return NULL if an error was encountered. Add
public API functions to retrieve error code and error message.

strbuf overflow in renderers and OOM in parser or renderers still
cause an abort.
2016-12-30 18:25:16 -07:00
John MacFarlane
636d6018ea Ran 'make format' to reformat code. 2016-10-11 14:51:42 +02:00
Yuki Izumi
8f80fb3369
Add test for NUL-LF sequence 2016-10-11 01:43:26 +11:00
John MacFarlane
b637b19f45 Modified api_test for change in "two blanks break out of a list." 2016-07-11 22:37:31 +01:00
Nick Wellnhofer
67f760a78f Fix chunk_set_cstr with suffix of current string
It's possible that cmark_chunk_set_cstr is called with a substring
(suffix) of the current string. Delay freeing of the chunk content
to handle this case correctly.

Fixes issue #139.
2016-07-03 12:18:43 +02:00
John MacFarlane
0b6805c0c5 Merge pull request #111 from PavloKapyshin/master
Add library option to render softbreaks as spaces
2016-04-09 11:35:58 -07:00
Mathieu Duponchelle
7dfe7fff11 api_test: fix leak
Replaced nodes are not automatically freed.
2016-03-26 15:45:54 -07:00
John MacFarlane
7cb92c313c Added api_test for #117. 2016-03-26 12:47:47 -07:00
Pavlo Kapyshin
ec64e9ea89 Add library option to render softbreaks as spaces 2016-03-18 10:28:22 +02:00
John MacFarlane
e1d1593f51 Automatic code reformat. 2016-01-18 09:33:43 -08:00
John MacFarlane
9409e2ee7e Adjusted api test for last commonmark renderer change. 2016-01-17 13:25:08 -08:00
John MacFarlane
93843bd2fe Added cmark_node_replace(oldnode, newnode).
API change.

I've found in using the API that this is very often
wanted.
2016-01-10 23:35:33 -08:00
John MacFarlane
9305d14f39 Fixed get_containing_block logic in src/commonmark.c.
This did not allow for the possibility that a node
might have no containing block, causing the commonmark
renderer to segfault if passed an inline node with no
block parent.
2016-01-08 13:26:06 -08:00
John MacFarlane
56501dc4d3 Added an api_test that segfaults.
render_commonmark on a non-block node.

Still don't know why.
2016-01-08 13:17:02 -08:00
John MacFarlane
37e2c4b2bf Added xml renderer test to API tests.
Closes #51.
2015-12-28 17:19:25 -08:00
John MacFarlane
9821520418 api_test: updated commonmark renderer test.
Removed a test we can't yet handle with the render interface.
The renderer isn't smart enough to escape a `-` that wraps to
the beginning of a line.
2015-12-28 17:10:07 -08:00
John MacFarlane
aaa0048c01 Added to commonmark renderer test. 2015-12-28 16:45:03 -08:00
John MacFarlane
ccc13fd3a0 Added commonmark renderer test (currently failing). 2015-12-28 16:35:54 -08:00
John MacFarlane
a980839495 Added simple latex renderer test to api tests. 2015-12-28 16:24:31 -08:00
John MacFarlane
1d9b4cb920 Added a minimal man renderer test to api tests. 2015-12-28 16:17:52 -08:00
John MacFarlane
11a29f6219 Reformat sources. 2015-12-28 16:05:42 -08:00
John MacFarlane
6e599f2ceb Rename NODE_HTML -> NODE_HTML_BLOCK, NODE_INLINE_HTML -> NODE_HTML_INLINE.
API change.  Sorry, but this is the time to break things,
before 1.0 is released.  This matches the recent changes to
CommonMark.dtd.
2015-12-28 11:46:33 -08:00
John MacFarlane
4811dc3ec2 Rename hrule -> thematic_break.
CMARK_NODE_HRULE -> CMARK_NODE_THEMATIC_BREAK.

However we've defined the former as the latter to keep
backwards compatibility.

See jgm/CommonMark 8fa94cb460f5e516b0e57adca33f50a669d51f6c
2015-12-22 22:55:39 -08:00
John MacFarlane
de6c5fb2c4 CMARK_NODE_HEADER -> CMARK_NODE_HEADING.
Defined CMARK_NODE_HEADER to CMARK_NODE_HEADING to ease
the transition.
2015-12-22 22:41:33 -08:00
John MacFarlane
a74295a1ea Rename 'header' -> 'heading'.
See jgm/CommonMark commit 0cdbcee4e840abd0ac7db93797b2b75ca4104314

Note that we have defined

cmark_node_get_header_level = cmark_node_get_heading_level
and
cmark_node_set_header_level = camrk_node_set_heading_level

for backwards compatibility in the API.
2015-12-22 22:18:03 -08:00
John MacFarlane
b8a916fbe1 Added api_tests for custom nodes. 2015-12-19 21:59:20 -08:00
Kevin Wojniak
ce0e58469f Remove need to disable MSVC warning 4267 2015-08-10 10:09:26 -07:00
Kevin Wojniak
6c51eb5a98 Remove need to disable MSVC warning 4244 2015-08-10 10:07:54 -07:00
Kevin Wojniak
722bc5df7e Remove need to disable MSVC warning 4244 2015-08-10 10:06:14 -07:00