[gobject-introspection] docwriter: Support markdown 3.x. Fixes #250



commit 287dbe9a066479a695769f96f8eea7af01b911aa
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Wed Dec 19 22:17:16 2018 +0100

    docwriter: Support markdown 3.x. Fixes #250
    
    The headerid extension no longer exists in 3.x. Use the toc extension instead.
    The toc_depth option was only added in 3.x so still try headerid first.

 .gitlab-ci/test-msys2-meson.sh |  4 ++--
 giscanner/docwriter.py         | 17 ++++++++++++++---
 2 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/.gitlab-ci/test-msys2-meson.sh b/.gitlab-ci/test-msys2-meson.sh
index 2d3952a8..da4c3eaf 100644
--- a/.gitlab-ci/test-msys2-meson.sh
+++ b/.gitlab-ci/test-msys2-meson.sh
@@ -20,6 +20,7 @@ pacman --noconfirm -S --needed \
     mingw-w64-$MSYS2_ARCH-python3 \
     mingw-w64-$MSYS2_ARCH-python3-pip \
     mingw-w64-$MSYS2_ARCH-python3-mako \
+    mingw-w64-$MSYS2_ARCH-python3-markdown \
     mingw-w64-$MSYS2_ARCH-libffi \
     mingw-w64-$MSYS2_ARCH-pkg-config \
     mingw-w64-$MSYS2_ARCH-cairo \
@@ -30,8 +31,7 @@ pacman --noconfirm -S --needed \
 export CCACHE_BASEDIR="${CI_PROJECT_DIR}"
 export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache"
 
-# FIXME: markdown: https://gitlab.gnome.org/GNOME/gobject-introspection/issues/250
-pip3 install --upgrade --user meson==0.48.2 flake8 markdown==2.6.11
+pip3 install --upgrade --user meson==0.48.2 flake8
 export PATH="$HOME/.local/bin:$PATH"
 
 # FIXME: https://github.com/Alexpux/MINGW-packages/pull/4064
diff --git a/giscanner/docwriter.py b/giscanner/docwriter.py
index 15e68433..7ccce59f 100644
--- a/giscanner/docwriter.py
+++ b/giscanner/docwriter.py
@@ -29,7 +29,6 @@ import tempfile
 from xml.sax import saxutils
 from mako.lookup import TemplateLookup
 import markdown
-from markdown.extensions.headerid import HeaderIdExtension
 
 from . import ast, xmlwriter
 from .utils import to_underscores
@@ -61,6 +60,18 @@ language_mimes = {
 }
 
 
+def get_headerid_ext():
+    try:
+        from markdown.extensions.headerid import HeaderIdExtension
+    except ImportError:
+        # markdown 3.x
+        from markdown.extensions.toc import TocExtension
+        return TocExtension(toc_depth=0)
+    else:
+        # markdown 2.x
+        return HeaderIdExtension(forceid=False)
+
+
 def make_page_id(node, recursive=False):
     if isinstance(node, ast.Namespace):
         if recursive:
@@ -1170,7 +1181,7 @@ class DevDocsFormatterGjs(DocFormatterGjs):
             'markdown.extensions.fenced_code',
             'markdown.extensions.nl2br',
             'markdown.extensions.attr_list',
-            HeaderIdExtension(forceid=False)
+            get_headerid_ext(),
         ])
 
     def format_function_name(self, func):
@@ -1258,7 +1269,7 @@ class DevDocsFormatterGjs(DocFormatterGjs):
             'markdown.extensions.fenced_code',
             'markdown.extensions.nl2br',
             'markdown.extensions.attr_list',
-            HeaderIdExtension(forceid=False)
+            get_headerid_ext(),
         ])
 
     def format_in_parameters(self, node):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]