Discuss Scratch

BlockWare
Scratcher
100+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

I am planning on making an HTML app that allows users to design forum posts the same simple way a user might create a Word document. It wouls be a lot easier for me if I understood what script reads the code of a post and returns what the post is supposed to look like.
Sorry if I am not being clear, and thanks for reading!
Note: If it is a PHP/backend script, only ST will be able to answer, I think.
WooHooBoy
Scratcher
1000+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

BlockWare
Scratcher
100+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

WooHooBoy wrote:

if you want the bbcode source https://scratch.mit.edu/discuss/post/1824006/source/

https://scratch.mit.edu/discuss/post/[post number]/source/
That is definitely helpful, though not what I was looking for (my first post wasn't very clear).
I'm looking for the script(s) that process(es) BBCode and then outputs a forum post.
blob8108
Scratcher
1000+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

Have a look at `convert_text_to_html` in https://github.com/LLK/s2forums/blob/master/djangobb_forum/util.py –that's part of the source code for the forums.

Alternatively, maybe you want to look at the postmarkup library the forums use to parse BBCode?
BlockWare
Scratcher
100+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

blob8108 wrote:

Have a look at `convert_text_to_html` in https://github.com/LLK/s2forums/blob/master/djangobb_forum/util.py –that's part of the source code for the forums.

Alternatively, maybe you want to look at the postmarkup library the forums use to parse BBCode?
Thanks! (I can follow the link due to my school's overprotective Internet filter) But where would I find the postmarkup library?
blob8108
Scratcher
1000+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

BlockWare wrote:

where would I find the postmarkup library?
You can also find that by searching GitHub: https://github.com/frol/postmarkup
BlockWare
Scratcher
100+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

blob8108 wrote:

BlockWare wrote:

where would I find the postmarkup library?
You can also find that by searching GitHub: https://github.com/frol/postmarkup
Thanks!
Jonathan50
Scratcher
1000+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

BlockWare wrote:

I can follow the link due to my school's overprotective Internet filter
ಠ_ಠ

BlockWare wrote:

But where would I find the postmarkup library?
https://code.google.com/archive/p/postmarkup/
jTron
Scratcher
100+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

You asked how the preview button works—here's from a front-end perspective:

When you click the preview button your browser POSTs to https://scratch.mit.edu/discuss/preview/ with data={bbcode}. The response, it looks like, is actually pretty gnarly considering (couldn't they just send back the html?) but you basically get a huge mess of <link>s, inline css, scripts (jquery, scratchblocks2 + translations), inline js (module headerey and other type stuff at the top, then it looks like for scratchblocks near the bottom), and, somewhere in all this, your actual post (innerHTML of `.post_body_html`).

For this post so far hitting “preview” sets you back about 7.4KB (3.6 gzipped) (+252.5/79 the first time for all the linked cruft) which seems like quite a bit for just previewing a bit of text…

Last edited by jTron (March 2, 2016 00:58:09)

-Io-
Scratcher
1000+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

jTron wrote:

You asked how the preview button works—here's from a front-end perspective:

When you click the preview button your browser POSTs to https://scratch.mit.edu/discuss/preview/ with data={bbcode}. The response, it looks like, is actually pretty gnarly considering (couldn't they just send back the html?) but you basically get a huge mess of <link>s, inline css, scripts (jquery, scratchblocks2 + translations), inline js (module headerey and other type stuff at the top, then it looks like for scratchblocks near the bottom), and, somewhere in all this, your actual post (innerHTML of `.post_body_html`).

For this post so far hitting “preview” sets you back about 7.4KB (3.6 gzipped) (+252.5/79 the first time for all the linked cruft) which seems like quite a bit for just previewing a bit of text…
The preview sends you back the whole page that needs to go into the preview iframe. Also, the <link>s are for the css needed, since they use stuff like class=“bb-bold”
Dylan5797
Scratcher
1000+ posts

What script turns the BBCode into a readable forum post (how does the 'Preview' button work)?

I wrote one, it's way smaller. It works but doesn't generate HTML, it returns an abstract syntax tree.


Perfect for spam checking

https://github.com/Dylan5797/BBCodeParser/blob/master/BBCodeParser.py

Powered by DjangoBB