rosscdh / mkdocs-markdownextradata-plugin

A MkDocs plugin that injects the mkdocs.yml extra variables into the markdown template
MIT License
84 stars 17 forks source link

json booleans are translated into python booleans #16

Closed peterw-ibm closed 4 years ago

peterw-ibm commented 4 years ago

When injecting a json file with a json boolean (true, false), in the html javascript this boolean shows up as a python boolean (True, False), causing javscript to fail.

rosscdh commented 4 years ago

please provide your setup .

Also please be very aware that the json files are to provide variables for use within a template. NOT to provide the json file as content for display.

you would be better off specifying a yaml file and then having a variable for your json content

my_vars.yaml

my_variables:
  name: blah
  example_json: |-
   {"name": "bob"}

this is basically an untested suggestion as your particular use-case was not in the scope when i originally created this. But would be cool to support

but if you are documenting apis you should really consider using something like readme.io and or swagger-ui or redoc which les you specify an openapi spec that you can inline comment and document

peterw-ibm commented 4 years ago

Hope this helps.

folder setup:

-- mkdocs.yml ---------------------------- site_name: Test markdownextradata booleans remote_branch: gh-pages remote_name: origin docs_dir: docs markdown_extensions:

-- index.md ---------------------

Test markdownextradata booleans

-- test.json ------------------------------------- { "some_string": "hello", "bool_false": false, "bool_true": true }

-- Browser console ---------------------------------- ReferenceError: False is not defined127.0.0.1:8000:66:41

-- Browser debugger --------------------------------

Test markdownextradata booleans

rosscdh commented 4 years ago

Yep, as noted in my previous comment; the purpose of this plugin is to provide variables to be used in your templates; not json strings "as" variables.

try the previously mentioned possiblity

my_variables:
  name: blah
  example_json: |-
   {"name": "bob"}

that "might" work. but currently this is a feature thats out of scope if not; if I get some time I may fix it but right now its OOS sorry. But feel free to make a PR.

rosscdh commented 4 years ago

So as promised (because im a sucker at 23:21) https://pypi.org/project/mkdocs-markdownextradata-plugin/0.1.5/

I have proven that the suggestion above works

you can see the test here: https://github.com/rosscdh/mkdocs-markdownextradata-plugin/blob/master/test/test_basic.py#L28