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

Configurable flexmark options #1123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

akruis
Copy link

@akruis akruis commented Mar 31, 2023

Hi,

we use schemaspy to document an internal database project. During the development it is very convenient to use the markdown editor of our Gitlab instance to write documentation for database objects using Gitlab-flavored markdown. Unfortunately schemaspy uses pegdown flavored markdown.

The flexmark processor is very flexible and can render many different markdown variants, but currently its configuration is hard wired. This merge request is a prove of concept to make the flexmark configuration an runtime option.

My Java is not the best any more and I'm not familiar with the implementation details of the schemaspy configuration. Therefore I used system properties instead of a proper integration with the schemaspy configuration. Clearly not production quality, but better than nothing.

To use the patch, I call schemaspy like this

    java -Dschemaspy.flexmark.options.class=org.schemaspy.util.FlexmarkJsOptions \
           -Dschemaspy.flexmark.options.js=flexmark.js -jar schemaspy.jar ...

The content of the file flexmark.js is

// Create a flexmark configuration
var getOptions = function() {
    // print('Hi there from Javascript');
    var Arrays = Java.type('java.util.Arrays');
    var MutableDataSet = Java.type('com.vladsch.flexmark.util.data.MutableDataSet');
    var Parser = Java.type('com.vladsch.flexmark.parser.Parser');
    var ParserEmulationProfile = Java.type('com.vladsch.flexmark.parser.ParserEmulationProfile');

    var AutolinkExtension = Java.type('com.vladsch.flexmark.ext.autolink.AutolinkExtension');
    var EmojiExtension = Java.type('com.vladsch.flexmark.ext.emoji.EmojiExtension');
    var EmojiImageType = Java.type('com.vladsch.flexmark.ext.emoji.EmojiImageType');
    var EmojiShortcutType = Java.type('com.vladsch.flexmark.ext.emoji.EmojiShortcutType');
    var StrikethroughExtension = Java.type('com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension');
    var TaskListExtension = Java.type('com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension');
    var TablesExtension = Java.type('com.vladsch.flexmark.ext.tables.TablesExtension');

    var options = new MutableDataSet();
    options.set(Parser.EXTENSIONS, Arrays.asList(
        AutolinkExtension.create(),
        EmojiExtension.create(),
        StrikethroughExtension.create(),
        TaskListExtension.create(),
        TablesExtension.create()
    ))
    // set GitHub table parsing options
        .set(TablesExtension.WITH_CAPTION, false)
        .set(TablesExtension.COLUMN_SPANS, false)
        .set(TablesExtension.MIN_HEADER_ROWS, 1)
        .set(TablesExtension.MAX_HEADER_ROWS, 1)
        .set(TablesExtension.APPEND_MISSING_COLUMNS, true)
        .set(TablesExtension.DISCARD_EXTRA_COLUMNS, true)
        .set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true)
    //.set(EmojiExtension.ROOT_IMAGE_PATH, emojiInstallDirectory())
        .set(EmojiExtension.USE_SHORTCUT_TYPE, EmojiShortcutType.GITHUB)
        .set(EmojiExtension.USE_IMAGE_TYPE, EmojiImageType.IMAGE_ONLY)
        .set(Parser.LISTS_ORDERED_LIST_MANUAL_START, true);

    options.setFrom(ParserEmulationProfile.GITHUB_DOC);
    options = options.toImmutable();
    return options;
};

CU Anselm

Anselm Kruis added 2 commits March 31, 2023 18:15
Usually schemaspy calls the markdown processor "flexmark"
with a hard coded set of options, that defines the "pegdown"
flavor of markdown. To change the flavor to an more modern
(and Git***-compatible) markdown-flavor one needs a different
set of options.

This commit makes it possible to configure a factory for the
flexmark options and provides a suitable factory class, that
uses javascript to define the options at runtime.
@npetzall
Copy link
Member

npetzall commented Apr 2, 2023

Sorry for the late reply I've been out sick, I'll try to have a look at how the configuration is done and what's required to configure flexmark-java.

I'm hoping that there might be a simpler solution than having to go thru JavaScript or at least make it simpler for users.

@npetzall
Copy link
Member

npetzall commented Apr 2, 2023

From flexmark-java:

For Versions 0.62.2 or below, Java 8 or above, Java 9+ compatible. For Versions 0.64.0 or above, Java 11 or above.

Might need to use < 0.64.0 for now, or make a decision on bumping java requirement. But that's a totally different issue.

@akruis
Copy link
Author

akruis commented Apr 3, 2023

Sorry for the late reply I've been out sick, I'll try to have a look at how the configuration is done and what's required to configure flexmark-java.

I'm hoping that there might be a simpler solution than having to go thru JavaScript or at least make it simpler for users.

Sure. Once you have a suitable set of flexmark options, you could provide a ready-to-use configuration. But being able to change the configuration details an runtime is valuable too.

Might need to use < 0.64.0 for now, or make a decision on bumping java requirement. But that's a totally different issue.

I upgraded, because I first thought that my rendering problems might be caused by a flexmark bug. And then I was to lazy to look for the documentation of older flexmark versions. Version 0.62.2 is the last version, that supports Java 8.

@npetzall
Copy link
Member

npetzall commented Apr 3, 2023

@akruis not ready to use but a simpler configuration file, so that it's easy to modify and use your own configuration.

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

Successfully merging this pull request may close these issues.

None yet

2 participants