Adds the CMark source into the plugin tree to be used when there is no `libcmark` package available using `pkg-config`. At present, my distro only ships the `cmark` utility but not the accompanying library or development packages, as well I do not believe msys2 provides a CMark package for Windows, so for now it will remain embedded as a backup.
The version embedded is v0.28.3, from commit 9f8ef820301951f36301c1a40d036cafeaa78619. A few trivial changes were made to allow libcmark to compile without its original CMake infrastructure. Only `cmark.h` and `cmark_version.h` were modified.
TODO: create a patch so the simple changes to upstream CMark library can be mechanically applied to newer versions.
All future complaints/requests about supporting various Markdown extensions should be addressed directly to the [CommonMark Project](http://commonmark.org/). You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany-plugins/pull/747
-- Commit Summary --
* Markdown: replace Discount and PEG Markdown with CMark
-- File Changes --
M build/markdown.m4 (54) M markdown/.gitignore (3) M markdown/Makefile.am (8) A markdown/cmark/COPYING (170) A markdown/cmark/Makefile.am (43) A markdown/cmark/blocks.c (1218) A markdown/cmark/buffer.c (279) A markdown/cmark/buffer.h (82) A markdown/cmark/case_fold_switch.inc (4327) A markdown/cmark/chunk.h (120) A markdown/cmark/cmark.c (43) A markdown/cmark/cmark.h (647) A markdown/cmark/cmark_ctype.c (44) A markdown/cmark/cmark_ctype.h (26) A markdown/cmark/cmark_version.h (7) A markdown/cmark/commonmark.c (475) A markdown/cmark/config.h.in (76) A markdown/cmark/entities.inc (2138) A markdown/cmark/houdini.h (51) A markdown/cmark/houdini_href_e.c (100) A markdown/cmark/houdini_html_e.c (66) A markdown/cmark/houdini_html_u.c (149) A markdown/cmark/html.c (341) A markdown/cmark/inlines.c (1342) A markdown/cmark/inlines.h (21) A markdown/cmark/iterator.c (121) A markdown/cmark/iterator.h (27) A markdown/cmark/latex.c (453) A markdown/cmark/main.c (189) A markdown/cmark/man.c (252) A markdown/cmark/node.c (858) A markdown/cmark/node.h (93) A markdown/cmark/parser.h (39) A markdown/cmark/references.c (146) A markdown/cmark/references.h (41) A markdown/cmark/render.c (185) A markdown/cmark/render.h (50) A markdown/cmark/scanners.c (13513) A markdown/cmark/scanners.h (55) A markdown/cmark/scanners.re (320) A markdown/cmark/utf8.c (317) A markdown/cmark/utf8.h (24) A markdown/cmark/xml.c (170) D markdown/peg-markdown/LICENSE (88) D markdown/peg-markdown/Makefile.am (29) D markdown/peg-markdown/README (1) D markdown/peg-markdown/README.markdown (213) D markdown/peg-markdown/markdown_lib.c (181) D markdown/peg-markdown/markdown_lib.h (27) D markdown/peg-markdown/markdown_output.c (1121) D markdown/peg-markdown/markdown_parser.leg (774) D markdown/peg-markdown/markdown_peg.h (72) D markdown/peg-markdown/odf.c (181) D markdown/peg-markdown/odf.h (11) D markdown/peg-markdown/parsing_functions.c (117) D markdown/peg-markdown/parsing_functions.h (17) D markdown/peg-markdown/peg-0.1.9/Makefile.am (10) D markdown/peg-markdown/peg-0.1.9/compile.c (717) D markdown/peg-markdown/peg-0.1.9/leg.c (1209) D markdown/peg-markdown/peg-0.1.9/leg.leg (292) D markdown/peg-markdown/peg-0.1.9/tree.c (352) D markdown/peg-markdown/peg-0.1.9/tree.h (108) D markdown/peg-markdown/peg-0.1.9/version.h (3) D markdown/peg-markdown/utility_functions.c (206) D markdown/peg-markdown/utility_functions.h (74) M markdown/src/Makefile.am (15) M markdown/src/viewer.c (36)
-- Patch Links --
https://github.com/geany/geany-plugins/pull/747.patch https://github.com/geany/geany-plugins/pull/747.diff
Also ping @evgeni, @sardemff7 et al. :smile:
For anyone interested in reviewing the non-build-related code, the crux of it [is here](https://github.com/geany/geany-plugins/pull/747/files#diff-fb832b7dde56a1134...).
For future me, diffs from upstream:
```patch @@ -1,10 +1,13 @@ #ifndef CMARK_H #define CMARK_H
+#include <stdbool.h> #include <stdio.h> -#include <cmark_export.h> #include <cmark_version.h>
+#define CMARK_EXPORT +#define CMARK_INLINE inline + #ifdef __cplusplus extern "C" { #endif ```
and
```patch @@ -1,7 +1,7 @@ #ifndef CMARK_VERSION_H #define CMARK_VERSION_H
-#define CMARK_VERSION ((@PROJECT_VERSION_MAJOR@ << 16) | (@PROJECT_VERSION_MINOR@ << 8) | @PROJECT_VERSION_PATCH@) -#define CMARK_VERSION_STRING "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@" +#define CMARK_VERSION ((0 << 16) | (28 << 8) | 3) +#define CMARK_VERSION_STRING "0.28.3"
#endif ```
@codebrainz why did you ping me? debian maintenance is done mostly by @hyperair these days. but cmark is available in debian and i guess we would not really care what you embed as a fallback.
@evgeni sorry, I wasn't aware, I just wanted to get some people who know the project and about packaging and Autotools to take a look, since that's mostly what this PR affects. Sorry for the (now two) pings. I did see that a `libcmark` package was added [very recently](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=840727), but I just embedded it until it's widely available. Thanks for your time.
b4n requested changes on this pull request.
I'd think `make distcheck` should be failing without cmark in the environment
@@ -1,2 +1 @@
-/peg-markdown/markdown_parser.c -/peg-markdown/peg-0.1.9/leg +
you could merely remove this file I believe
@@ -1,11 +1,5 @@
include $(top_srcdir)/build/vars.auxfiles.mk
-SUBDIRS = - -if MARKDOWN_PEG_MARKDOWN -SUBDIRS += peg-markdown -endif - -SUBDIRS += src docs +SUBDIRS = cmark src docs
I would rather not recurse inside *cmark* if it isn't enabled (as it was done for *peg-markdown*). But either works, so if you prefer this it's not a problem.
@@ -0,0 +1,43 @@
+if MD_BUILTIN_CMARK + +noinst_LTLIBRARIES = libcmark.la + +libcmark_la_SOURCES = \ + blocks.c \ + buffer.c \ + buffer.h \ + chunk.h \ + cmark.c \ + cmark_ctype.c \ + cmark_ctype.h \ + cmark.h \
you miss at least *cmark_version.h*, so it will not be included in the tarball (as it's not listed anywhere I can see). Check witt the *distcheck* make target, and obviously on an environment lacking the cmark library (or explicitly enabling the builtin copy)
@@ -0,0 +1,43 @@
+if MD_BUILTIN_CMARK + +noinst_LTLIBRARIES = libcmark.la + +libcmark_la_SOURCES = \ + blocks.c \ + buffer.c \ + buffer.h \ + chunk.h \ + cmark.c \ + cmark_ctype.c \ + cmark_ctype.h \ + cmark.h \
you could generate the *cmark_version.h* automatically from a *cmark_version.h.in* fairly easily. Unfortunately the placeholder names are not namespaced properly (`PROJECT_`) so it wouldn't be too clean to replace them with the proper Autotools feature (which is sad, as it makes it super trivial, a matter of `AC_SUBST`ituing the macros and calling `AC_CONFIG_FILES([cmark/cmark_version.h])`), but you can do that with a `sed` call easily, something like this:
```makefile CMARK_VERSION_MAJOR=0 CMARK_VERSION_MINOR=28 CMARK_VERSION_PATCH=3
CLEANFILES = cmark_version.h EXTRA_DIST = cmark_version.h.in
cmark_version.h: cmark_version.h.in Makefile $(SED) -e 's,[@]PROJECT_VERSION_MAJOR[@],$(CMARK_VERSION_MAJOR),g' \ -e 's,[@]PROJECT_VERSION_MINOR[@],$(CMARK_VERSION_MINOR),g' \ -e 's,[@]PROJECT_VERSION_PATCH[@],$(CMARK_VERSION_PATCH),g' \ < $(srcdir)/$@.in > $@ ``` Don't forget to check for [`AC_PROG_SED`](https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Particu...) in *markdown.m4* when the plugin is enabled (I would think it's already done somewhere (libtool?), but doing it for the plugin is safe(r))
Likewise, you could generate *cmark_export.h* to your needs (and if it has to include *stdbool.h* for a hack of some kind, so be it).
That's just suggestions for easing the update of the embedded library by minimizing and hopefully removing any difference. I would think their *cmark_version.h* file is auto-generated (or at least processed) anyway, so that should not create additional diversion.
@@ -0,0 +1,76 @@
+#ifndef CMARK_CONFIG_H +#define CMARK_CONFIG_H
this file seems useless in the current setup. However, some of its content could be moved to Autotools…
@@ -0,0 +1,76 @@
+#ifndef CMARK_CONFIG_H +#define CMARK_CONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#cmakedefine HAVE_STDBOOL_H
`AC_CHECK_HEADERS([stdbool.h])`
@@ -0,0 +1,76 @@
+#ifndef CMARK_CONFIG_H +#define CMARK_CONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#cmakedefine HAVE_STDBOOL_H + +#ifdef HAVE_STDBOOL_H + #include <stdbool.h> +#elif !defined(__cplusplus) + typedef char bool; +#endif
Trickier, because Autotools doesn't really have a clean way of force-including stuff, and this file is a mere *config.h*… one way could be having a second *config.h* just for cmark, but I'm not sure how to manage this with stock Autotools, short of manually generating that one (e.g. having a template and performing the replacements or using `AC_SUBST`/`AC_CONFIG_FILES`).
+#ifndef CMARK_CONFIG_H
+#define CMARK_CONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#cmakedefine HAVE_STDBOOL_H + +#ifdef HAVE_STDBOOL_H + #include <stdbool.h> +#elif !defined(__cplusplus) + typedef char bool; +#endif + +#cmakedefine HAVE___BUILTIN_EXPECT
You might want to add a check for `__builtin_expect()` that `AC_DEFINE`s `HAVE___BUILTIN_EXPECT`. I'm not sure how you check for this, but an `AC_TRY_COMPILE` would do I guess.
+#ifdef __cplusplus +extern "C" { +#endif + +#cmakedefine HAVE_STDBOOL_H + +#ifdef HAVE_STDBOOL_H + #include <stdbool.h> +#elif !defined(__cplusplus) + typedef char bool; +#endif + +#cmakedefine HAVE___BUILTIN_EXPECT + +#cmakedefine HAVE___ATTRIBUTE__
Same
+#ifdef HAVE_STDBOOL_H + #include <stdbool.h> +#elif !defined(__cplusplus) + typedef char bool; +#endif + +#cmakedefine HAVE___BUILTIN_EXPECT + +#cmakedefine HAVE___ATTRIBUTE__ + +#ifdef HAVE___ATTRIBUTE__ + #define CMARK_ATTRIBUTE(list) __attribute__ (list) +#else + #define CMARK_ATTRIBUTE(list) +#endif
Or instead of defining `HAVE___ATTRIBUTE__`, just `AC_DEFINE` `CMARK_ATTRIBUTE` as appropriate. Though, I'm not sure it's possible to define a macro taking arguments… at worse, just define a custom `CPPFLAG` playing with `-D` I guess
+#cmakedefine HAVE___ATTRIBUTE__ + +#ifdef HAVE___ATTRIBUTE__ + #define CMARK_ATTRIBUTE(list) __attribute__ (list) +#else + #define CMARK_ATTRIBUTE(list) +#endif + +#ifndef CMARK_INLINE + #if defined(_MSC_VER) && !defined(__cplusplus) + #define CMARK_INLINE __inline + #else + #define CMARK_INLINE inline + #endif +#endif
similar here, you could check for availability and `AC_DEFINE` `CMARK_INLINE`, or use `-D`
- #define CMARK_ATTRIBUTE(list) __attribute__ (list)
+#else + #define CMARK_ATTRIBUTE(list) +#endif + +#ifndef CMARK_INLINE + #if defined(_MSC_VER) && !defined(__cplusplus) + #define CMARK_INLINE __inline + #else + #define CMARK_INLINE inline + #endif +#endif + +/* snprintf and vsnprintf fallbacks for MSVC before 2015, + due to Valentin Milea http://stackoverflow.com/questions/2915672/ +*/
I'm not sure if we support compiling with MSVC at all, but if it's the case and cmark requires properly behaving `[v]snprintf()` it might be important to have a similar thing.
- node.c \
+ node.h \ + parser.h \ + references.c \ + references.h \ + render.c \ + render.h \ + scanners.c \ + scanners.h \ + utf8.c \ + utf8.h \ + xml.c + +EXTRA_DIST = \ + case_fold_switch.inc \ + entities.inc
you also miss *scanners.re*.
codebrainz commented on this pull request.
@@ -1,2 +1 @@
-/peg-markdown/markdown_parser.c -/peg-markdown/peg-0.1.9/leg +
Oops.
codebrainz commented on this pull request.
@@ -1,11 +1,5 @@
include $(top_srcdir)/build/vars.auxfiles.mk
-SUBDIRS = - -if MARKDOWN_PEG_MARKDOWN -SUBDIRS += peg-markdown -endif - -SUBDIRS += src docs +SUBDIRS = cmark src docs
I'm indifferent.
codebrainz commented on this pull request.
@@ -0,0 +1,43 @@
+if MD_BUILTIN_CMARK + +noinst_LTLIBRARIES = libcmark.la + +libcmark_la_SOURCES = \ + blocks.c \ + buffer.c \ + buffer.h \ + chunk.h \ + cmark.c \ + cmark_ctype.c \ + cmark_ctype.h \ + cmark.h \
Good call on the `cmark_version.h` missing. I tried to run `make distcheck` but it failed in what seemed like not my plugin's code (in `util` IIRC), will have to try again.
Will look at generating `cmark_version.h`, I was too lazy to bother as the changes I made are quite trivial to reproduce if/when I update the embedded version, but it is better to generate it. I briefly looked at `cmark_export.h.in` but I couldn't really figure out where it came from, and I can't read the awful `cmake` language.
codebrainz commented on this pull request.
@@ -0,0 +1,76 @@
+#ifndef CMARK_CONFIG_H +#define CMARK_CONFIG_H
I don't think I want to care about anything in this file that I can trivially stub-out. Maybe I could just drop it, will have to look closer. Same for most of below comments on this file.
codebrainz commented on this pull request.
- node.c \
+ node.h \ + parser.h \ + references.c \ + references.h \ + render.c \ + render.h \ + scanners.c \ + scanners.h \ + utf8.c \ + utf8.h \ + xml.c + +EXTRA_DIST = \ + case_fold_switch.inc \ + entities.inc
Oops, I meant to delete that file and just use the pre-generated code from upstream.
b4n commented on this pull request.
@@ -0,0 +1,43 @@
+if MD_BUILTIN_CMARK + +noinst_LTLIBRARIES = libcmark.la + +libcmark_la_SOURCES = \ + blocks.c \ + buffer.c \ + buffer.h \ + chunk.h \ + cmark.c \ + cmark_ctype.c \ + cmark_ctype.h \ + cmark.h \
About distcheck failure in *util* I don't know but could believe it, I'm afraid nobody tried it since util was introduced. I'll try to get a look into this when I can.
I briefly looked at `cmark_export.h.in` but I couldn't really figure out where it came from
Isn't the *.in* the source itself? Usually it's the suffix for files that will be processed, and the suffix is stripped from the output filename.
codebrainz commented on this pull request.
@@ -0,0 +1,43 @@
+if MD_BUILTIN_CMARK + +noinst_LTLIBRARIES = libcmark.la + +libcmark_la_SOURCES = \ + blocks.c \ + buffer.c \ + buffer.h \ + chunk.h \ + cmark.c \ + cmark_ctype.c \ + cmark_ctype.h \ + cmark.h \
Sorry, I made a typo with the `.in` suffix, it's just `cmark_export.h` and I have no clue where it comes from, it's not [in the sources](https://github.com/commonmark/cmark/tree/0.28.3/src), I can only suppose that it's entirely generated from CMake, but I couldn't stomach reading that horrid language.
https://github.com/geany/geany-plugins/issues/589 https://github.com/geany/geany-plugins/issues/651
https://github.com/geany/geany-plugins/pull/747
I've recently upgraded to Ubuntu 20.04 and I see that now `libcmark` is packaged separately, unfortunately it has a broken pkg-config file. I was also excited to see that there's a Github fork `libcmark-gfm` that features Github Flavoured Markdown, which would add support for some of the widely requested features (ex. tables), but again, unfortunately the pkg-config file for this one is entirely missing (it's upstream but not in the Ubuntu package).
Grrrrr....
github-comments@lists.geany.org