Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

codebrainz
Copy link
Member

@codebrainz codebrainz commented May 24, 2018

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, 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 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.

Fixes: #589, #651.

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/).
@codebrainz codebrainz requested review from hyperair, dmaphy, b4n and frlan May 24, 2018 08:28
@codebrainz
Copy link
Member Author

Also ping @evgeni, @sardemff7 et al. 😄

@codebrainz
Copy link
Member Author

For anyone interested in reviewing the non-build-related code, the crux of it is here.

@codebrainz
Copy link
Member Author

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

@evgeni
Copy link
Contributor

evgeni commented May 24, 2018

@codebrainz why did you ping me? :)
debian maintenance is done mostly by @hyperair these days - I am rather busy with other things.
but cmark is available in debian and i guess we would not really care what you embed as a fallback.

@codebrainz
Copy link
Member Author

@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, but I just embedded it until it's widely available. Thanks for your time.

Copy link
Member

@b4n b4n left a 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

Copy link
Member

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

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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 \
Copy link
Member

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)

Copy link
Member

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_SUBSTituing 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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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…

Copy link
Member Author

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
Copy link
Member

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__
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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/
*/
Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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.

@codebrainz
Copy link
Member Author

codebrainz commented May 27, 2020

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 extensions (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....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CommonMark plugin
4 participants