-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown: replace Discount and PEG Markdown with CMark #747
base: master
Are you sure you want to change the base?
Conversation
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/).
Also ping @evgeni, @sardemff7 et al. 😄 |
For anyone interested in reviewing the non-build-related code, the crux of it is here. |
For future me, diffs from upstream: @@ -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 @@ -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? :) |
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could merely remove this file I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops.
endif | ||
|
||
SUBDIRS += src docs | ||
SUBDIRS = cmark src docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm indifferent.
cmark.c \ | ||
cmark_ctype.c \ | ||
cmark_ctype.h \ | ||
cmark.h \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, I can only suppose that it's entirely generated from CMake, but I couldn't stomach reading that horrid language.
@@ -0,0 +1,76 @@ | |||
#ifndef CMARK_CONFIG_H | |||
#define CMARK_CONFIG_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file seems useless in the current setup. However, some of its content could be moved to Autotools…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
extern "C" { | ||
#endif | ||
|
||
#cmakedefine HAVE_STDBOOL_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AC_CHECK_HEADERS([stdbool.h])
|
||
#cmakedefine HAVE___BUILTIN_EXPECT | ||
|
||
#cmakedefine HAVE___ATTRIBUTE__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
#define CMARK_ATTRIBUTE(list) __attribute__ (list) | ||
#else | ||
#define CMARK_ATTRIBUTE(list) | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
#else | ||
#define CMARK_INLINE inline | ||
#endif | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar here, you could check for availability and AC_DEFINE
CMARK_INLINE
, or use -D
|
||
/* snprintf and vsnprintf fallbacks for MSVC before 2015, | ||
due to Valentin Milea http://stackoverflow.com/questions/2915672/ | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
||
EXTRA_DIST = \ | ||
case_fold_switch.inc \ | ||
entities.inc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you also miss scanners.re.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I meant to delete that file and just use the pre-generated code from upstream.
I've recently upgraded to Ubuntu 20.04 and I see that now Grrrrr.... |
Adds the CMark source into the plugin tree to be used when there is no
libcmark
package available usingpkg-config
. At present, my distro only ships thecmark
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, replacing the previously embedded PEG Markdown and the externally linked Discount markdown library.The version embedded is v0.28.3. A few trivial changes were made to allow libcmark to compile without its original CMake infrastructure. Only
cmark.h
andcmark_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.
Fixes: #589, #651.