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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 9 additions & 45 deletions build/markdown.m4
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
dnl _CHECK_LIBMARKDOWN([action-if-found], [action-if-not-found])
dnl Searches for libmarkdown and define HAVE_MKDIO_H, LIBMARKDOWN_LIBS and
dnl LIBMARKDOWN_CFLAGS
AC_DEFUN([_CHECK_LIBMARKDOWN],
[
old_LIBS=$LIBS
LIBS=
LIBMARKDOWN_LIBS=
LIBMARKDOWN_CFLAGS=
AC_SEARCH_LIBS([mkd_compile], [markdown],
[AC_CHECK_HEADERS([mkdio.h],
[LIBMARKDOWN_LIBS=$LIBS
LIBMARKDOWN_CFLAGS=
$1],
[$2])],
[$2])
AC_SUBST([LIBMARKDOWN_CFLAGS])
AC_SUBST([LIBMARKDOWN_LIBS])
LIBS=$old_LIBS
])

AC_DEFUN([GP_CHECK_MARKDOWN],
[
GP_ARG_DISABLE([markdown], [auto])
AC_ARG_ENABLE([peg-markdown],
[AS_HELP_STRING([--enable-peg-markdown],
[Whether to use Peg-Markdown library [[default=auto]]])],
[enable_peg_markdown=$enableval],
[enable_peg_markdown=auto])

dnl check which markdown library to use
AS_IF([test "x$enable_markdown" != xno &&
test "x$enable_peg_markdown" != xyes],
[_CHECK_LIBMARKDOWN([enable_peg_markdown=no],
[AS_IF([test "x$enable_peg_markdown" != xno],
[enable_peg_markdown=yes],
[test "x$enable_markdown" = xyes],
[AC_MSG_ERROR([libmarkdown not found])],
[enable_markdown=no
AC_MSG_WARN([libmarkdown not found, disabling Markdown plugin])])])])
AM_CONDITIONAL([MARKDOWN_PEG_MARKDOWN],
[test "x$enable_peg_markdown" = xyes])
dnl fancy status
AS_IF([test "x$enable_peg_markdown" = xyes],
[markdown_library=peg-markdown],
[markdown_library=libmarkdown])
GP_STATUS_FEATURE_ADD([Markdown library], [$markdown_library])
AS_IF([test "x$enable_markdown" != "xno"], [
PKG_CHECK_MODULES([CMARK],
[libcmark],
[md_enable_builtin_cmark=no],
[md_enable_builtin_cmark=yes])
])

AM_CONDITIONAL([MD_BUILTIN_CMARK], [test x$md_enable_builtin_cmark = xyes])

GTK_VERSION=2.16
WEBKIT_VERSION=1.1.13
Expand All @@ -62,8 +27,7 @@ AC_DEFUN([GP_CHECK_MARKDOWN],
AC_CONFIG_FILES([
markdown/Makefile
markdown/src/Makefile
markdown/cmark/Makefile
markdown/docs/Makefile
markdown/peg-markdown/Makefile
markdown/peg-markdown/peg-0.1.9/Makefile
])
])
3 changes: 1 addition & 2 deletions markdown/.gitignore
Original file line number Diff line number Diff line change
@@ -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.

8 changes: 1 addition & 7 deletions markdown/Makefile.am
Original file line number Diff line number Diff line change
@@ -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
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.


plugin = markdown
170 changes: 170 additions & 0 deletions markdown/cmark/COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
Copyright (c) 2014, John MacFarlane

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-----

houdini.h, houdini_href_e.c, houdini_html_e.c, houdini_html_u.c

derive from https://github.com/vmg/houdini (with some modifications)

Copyright (C) 2012 Vicent Martí

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

-----

buffer.h, buffer.c, chunk.h

are derived from code (C) 2012 Github, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

-----

utf8.c and utf8.c

are derived from utf8proc
(<http://www.public-software-group.org/utf8proc>),
(C) 2009 Public Software Group e. V., Berlin, Germany.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

-----

The normalization code in normalize.py was derived from the
markdowntest project, Copyright 2013 Karl Dubost:

The MIT License (MIT)

Copyright (c) 2013 Karl Dubost

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-----

The CommonMark spec (test/spec.txt) is

Copyright (C) 2014-15 John MacFarlane

Released under the Creative Commons CC-BY-SA 4.0 license:
<http://creativecommons.org/licenses/by-sa/4.0/>.

-----

The test software in test/ is

Copyright (c) 2014, John MacFarlane

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 changes: 43 additions & 0 deletions markdown/cmark/Makefile.am
Original file line number Diff line number Diff line change
@@ -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 \
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.

commonmark.c \
houdini.h \
houdini_href_e.c \
houdini_html_e.c \
houdini_html_u.c \
html.c \
inlines.c \
inlines.h \
iterator.c \
iterator.h \
latex.c \
man.c \
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
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.


endif
Loading