UniversalDevicesInc / udi_python_interface

A python interface module for Polyglot version 3.x
MIT License
4 stars 2 forks source link

markdown2 conversion is not supporting fenced-code-blocks #30

Closed sejgit closed 3 months ago

sejgit commented 3 months ago

Currently no "extras" are turned on in the markdown2 conversion of docs such as POLYGLOG_CONFIG.md , fenced-code-blocks are now considered standard part of markdown, so this confuses developers that it is not done correctly in PG3. This also makes is harder to make good docs. (btw: I am using fenced-code-blocks in this GitHub issue)

see https://github.com/trentm/python-markdown2/wiki/Extras

I have added code to my plugins to pre-process my docs with this on using the included markdown2 library, but a better solution would be to include in the udi-interface so everyone gets the advantage.

Two solutions:

  1. specific solution, just turn it on in the getMarkDownData function

    def getMarkDownData(self, fileName):
        data = ''
        if os.path.isfile(fileName):
            data = markdown2.markdown_path(fileName, extras=[fenced-code-blocks, cuddled-lists])
  2. general solution, where you let the user add any extra they want. Below is one non-breaking version of the setCustomParamsDoc & getMarkDownData functions which could work

 def setCustomParamsDoc(self, html=None, mdextras=None):
        """ Set the configuration help document.   """
        data = ''
        if html == None:
                html = self.getMarkDownData(
                        Interface.CUSTOM_CONFIG_DOCS_FILE_NAME, mdextras)
        LOGGER.debug('Sending {} to Polyglot.'.format('customparamsdoc'))
        message = {'set': [{'key': 'customparamsdoc', 'value': html}]}
        self.send(message, 'custom')

def getMarkDownData(self, fileName, mdextras=None):
        data = ''
        if os.path.isfile(fileName):
            data = markdown2.markdown_path(fileName, extras=mdextras)
        return data
BenoitMercier commented 3 months ago

I went with option 1 so it's easier to use. Please see version 3.3.11, just published now.

sejgit commented 3 months ago

works like a charm thanks Benoit, much appreciated!