Gatsby & GraphQL: Transforming a String field into markdown - graphql

I have a GraphQL schema on a headless CMS. I'm using gatsby-source-graphql on a Gatsby site to get data from it.
There is a content field MyType_BlogPost.body of type String. This contains markdown code.
Is it possible to transform (with gatsby-transformer-remark) that into MarkdownRemark (or similar) so that it will automatically get subfields like html that contain the data one would expect (html code transformed from the markdown source)? I suspect subfields would be the way to do this, but I'm not 100 % of that.
I also suspect this could help but I'm not sure: https://www.gatsbyjs.org/docs/schema-customization/
Thank you.

If the field contains markdown code which you would like to transform into html, you should be able to do that using remark.
Remark is the library that gatsby-transformer-remark uses under the hood.
https://remark.js.org/
Specifically, look at the API section in their docs.

Related

Python Sphinx Validate and update schema

I'm using Sphinx to maintain docs on a project, I am generating a jsonschema document from a tool where all properties of objects are listed.
Those objects properties are documented in rst files, I need to:
I've managed to read the rst files in the doctree-resolved event, and match with the json property, but I'm not sure if this is the best approach since I need
a) check all properties are documented, this is almost donde, I can mark on the json properties found and then check the json at the end.
b) Copy the description retrieved from the doctree object in the json (adding a property to the json) the format I need is markup, so I need to figure out how to convert a doctree node(set) to markup. Also the url links should be working at this stage. Also if markdown is not possible converting the fragment to html then to markdown might be easier
I don't know if I'm in the right path or should I write a builder instead?
Thanks

Keystone.js Content field type rendering best practice

I have a field with type Content which I'd like to render into html. From GraphQL endpoint, I receive a slate.js structure like
"contentExtended": {
"document": "{\"object\":\"document\",\"data\":{},\"nodes\":[{\"object\":\"block\",\"type\":\"paragraph\",\"data\":{},\"nodes\":[{\"object\":\"text\",\"text\":\"Test extended\",\"marks\":[]}]},{\"object\":\"block\",\"type\":\"paragraph\",\"data\":{},\"nodes\":[{\"object\":\"text\",\"text\":\"\",\"marks\":[]}]},{\"object\":\"block\",\"type\":\"cloudinaryImage\",\"data\":{\"_joinIds\":[\"5feb1aad43a7940689283e62\"]},\"nodes\":[{\"object\":\"block\",\"type\":\"image\",\"data\":{},\"nodes\":[{\"object\":\"text\",\"text\":\"\",\"marks\":[]}]},{\"object\":\"block\",\"type\":\"caption\",\"data\":{},\"nodes\":[{\"object\":\"text\",\"text\":\"\",\"marks\":[]}]}]},{\"object\":\"block\",\"type\":\"paragraph\",\"data\":{},\"nodes\":[{\"object\":\"text\",\"text\":\"\",\"marks\":[]}]}]}"
},
where contentExtended is the name of my field.
Note that the document also contains references to cloudinaryImage elsewhere in the GraphQL query result, therefore I assume that it's up to Keystone.js to know how to render it.
I'd like to render it into a html code that I'll use in my blog app, with least effort possible.
What is the recommended and correct way of doing that?
for reference, keystone graphql schema I have; I'm fetching posts with allPosts query.
https://gist.github.com/Firfi/42c9fd94c738cb463e4d7e7e28de751b
Keystone uses SlateJS v0.47, it has a different format than modern SlateJS.
Basically you are on your own, Keystone won't help you render it.
Here's an example how I do basic rendering: https://gist.github.com/dimaip/0454b58d360f26c1e6a87310ace61f8c
I don't use cloudinary, so not sure how you should render it, but I guess you could use the images's id (5feb1aad43a7940689283e62) to build a url?

VuePress: How to modify the markdown content

VuePress (v1) provides this API to access the page context: https://v1.vuepress.vuejs.org/plugin/option-api.html#extendpagedata
I can access these properties but I can't change the value of _content for instance.
I would like to modify (replace some regexp) the markdown before it get's rendered by Vue (an even before it's get parsed by the markdown parser).
Maybe it makes more sense to do it with a markdown-it plugin using the chainmarkdown API but I don't know how exactly. But the question is more how to write a plugin for markdown-it which can modify the content before even parsing, because I need the raw text.
Here is one markdown-it plugin that allows you to do exactly that by defining regular expressions: https://www.npmjs.com/package/markdown-it-regexp

ApiBlueprints parameter that yield result like Stripe's errors "attributes"?

I'm new to Stripe and I'd like generate a result that looks like the "Attributes" part of the Errors part : https://stripe.com/docs/api/curl#errors
It's looks like a table with two column, even though it's not a table.
I don't know how I can make this.
For information, I'm using Aglio to generate the template.
Cyril,
There is no easy way to do this in Markdown that I know of. You have two options:
Create your own layout template that manually adds this information, then tell aglio to use it.
Include some basic HTML in your API Blueprint. Here is an example. It just creates a definition list which describes the error attributes using the same CSS that already exists on the page to describe URI parameters.
You can use Markdown to create the tables of response types and codes, and if you want to use a three-column layout you can use the middle and right CSS classes.
Hope this helps!

Is it possible to specify parameters which go into the post body with blueprint?

I'd like to be able to document the parameters as if they were URL parameters, since I like how that bit of documentation renders a handy table. However, in my API, I would like those paremeters to plug into the JSON body rather than the URL. Is there a way to achieve this?
The dedicated syntax for describing, discussing (and thus also validating) message-body is in the making.
It will be based on the Markdown Syntax for Object Notation, similar to the actual URI Parameters description syntax (eventually these two should converge).
Also see related How to specify an optional element for a json request object and Is it possible to document what JSON response fields are? questions.

Resources