Closed marcus-at-localhost closed 2 years ago
@nightpool created a solution in JS: https://gist.github.com/nightpool/2fd5c94ef222bf67f9ad58a7a739a26f#file-01-npf-js-L168-L247
I modified this file to remove the library dependencies while implementing it in my browser-facing project, the Outbox for Tumblr extension, here: https://github.com/AprilSylph/Outbox-for-Tumblr/blob/f732885141cd22fd2822cd8f7e310b3d055daedd/src/lib/npf.js#L198-L277
turning inline formatting into HTML is, in fact, Very Complicated, unfortunately. there are probably more straightforward solutions than the one I came up with though, I was very picky about having extraneous tags like <em></em><a href=""><em>link</em></a>
. most people probably don't need to worry about that much (although for a
tags having extra can somewhat affect accessibility)
(also for people reading this: please note that npf.js is published under the AGPL, and you'll need to abide by the terms of that license if you want to adapt it into your project like April has)
@AprilSylph @nightpool thank you so much for giving insight into the concept of rendering npf.
Thanks for passing along that implementation @AprilSylph @nightpool -- I've also passed along this request as yet another great reason for us to open source the NPF => HTML parts of our frontend code (really, we should just open source all of it, imo 😅).
I'm having a hard time to understand how to create HTML from inline formatting in text blocks: https://github.com/tumblr/docs/blob/master/npf-spec.md#inline-formatting-within-a-text-block
What would it look like in JS/Pseudocode to turn the examples into HTML - I can't find any reference online.
The same for the whole NPF object, although inline styles are ones I'm struggling with.
Thank you!