Coder Social home page Coder Social logo

Comments (12)

timovn avatar timovn commented on May 18, 2024

For the <hr/>, we might convert it to <hr></hr> first, than parse for <p> and in the end convert it back to <hr/>. It’s a bit like Gecko DOM parser seem to work : the DOM tree also contains such things as <br></br> (even if the source document does not).
I’m open to other suggestions for this.

I’ll be happy to see the PR for the refactoring in either cases and put it to the tests.

I’m also asking myself if this function could need a major refactoring, using LibXML. But it could heavily conflict if the user input contains non-valid HTML, scripts or other stuff.

The purpose of this function is to make nicer HTML (instead of doing a nl2br()). This is usefull for applications like Pocket™, Readability.js and screen-readers that format paragraphs in specific ways.

from blogotext.

BoboTiG avatar BoboTiG commented on May 18, 2024

In theory the user input is BBCode formated. For the few who write raw HTML, if the code is bad it is not an error of BlogoText. I used to write raw HTML sometimes but now there is [code=language].
If there were a hr BBCode I think I will not have to write raw HTML anymore.

Do you know if a lot of people write scripts into the post content?
Perhaps you could use a function with libXML and in case of error fallback to this function?

from blogotext.

timovn avatar timovn commented on May 18, 2024

I use much of HTML all the time. No BBCode or markdown will replace its power.
A native HR tag in BBCode could help, and there was such a tag in the past but it would not solve the problem here : parse_texte_paragraphs() always gets HTML as parameter. So the BBCode would be transformed to HTML before the functions is called.

For that, at this point I don’t have any other idea than the intermediate tag (the same trick I use for the [code] tag, transformed into <prebtcode> and then in <pre>.

from blogotext.

BoboTiG avatar BoboTiG commented on May 18, 2024

You are right, using the same trick will be OK.
I will send the PR after your modifications, it is nothing big.

from blogotext.

timovn avatar timovn commented on May 18, 2024

It is done for the hr.
I noticed that the tbody element was forgotten in the block elements and added it also.

from blogotext.

BoboTiG avatar BoboTiG commented on May 18, 2024

It is much better :)
I just found that input blocks are wrong, but it is an unusual special case.

from blogotext.

timovn avatar timovn commented on May 18, 2024

You mean output ?

from blogotext.

BoboTiG avatar BoboTiG commented on May 18, 2024

No, input of forms.
I do not think it is needed to handle this case.

from blogotext.

timovn avatar timovn commented on May 18, 2024

I don’t understand : which inputs?

from blogotext.

BoboTiG avatar BoboTiG commented on May 18, 2024

I talking about manually add a form into a post :)

from blogotext.

timovn avatar timovn commented on May 18, 2024

Aha! But I didn’t planned to support that :O

If we really want to support the totality of HTML elements, we should add them all, and make a special regex for all the self-closing HTML tags.

It might then become quite hard to do to support everything : attributes for instance, can contain actual HTML and/or JS (with fancy characters, including HTML). It’s not impossible but it might be very tricky:
http://lehollandaisvolant.net/?mode=links&id=20130322003640
http://lehollandaisvolant.net/?mode=links&id=20130322223827

IMHO, there would be too much energy put into that for something not widely used and already having a solution.
There is an easy way to make everything work fine, that is not using any \n in the text you enter.

So, don’t do this:

<form>
<fieldset>
<label for="input">Blah</label>
<input id="Blah" value="something here"/>
</fieldset>
</form>

But this:

<form><fieldset><label for="input">Blah</label><input id="Blah" value="something here"/></fieldset></form>

It is dirty and undocumented, but it works and does validate with W3.

from blogotext.

BoboTiG avatar BoboTiG commented on May 18, 2024

Thanks for the trick! And yes, you are right, no need to implement such a thing ^^

from blogotext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.