View Single Post
Old 06-29-2020, 11:05 AM   #21
Mister L
Groupie
Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.
 
Posts: 179
Karma: 91148
Join Date: Jun 2010
Device: Sony 350
Quote:
Originally Posted by DiapDealer View Post
You misunderstood me. I wasn't really asking for human answers to most of those questions. I was asking what kind of spaghetti logic would be required within a plugin to get the plugin to always make the "right" decisions on its own? A human can look at the code and easily (sometimes) see where the new tag should be created. A script has to parse all of the html (and make informed guesses about where it makes sense to put it semantically speaking) to avoid creating malformed or improperly nested tags.
I do see your point, but I think there might be solutions to avoid making things more complicated than they need to be. In many cases the toc will link to the file. So the added tag would be the first tag in that file. No need to worry about nesting problems or malformed tags in that case.

If the link goes to somewhere inside that file, there will be an id, and the id is necessarily already in a tag of some kind; many times it will be an h tag already. Regardless, I think the easiest solution there is just to add the title directly to the existing tag with the id, even if it's not an h*:
<h1 id="tocid01"> becomes <h1 id="tocid01" title="Title of this toc item">
or
<a id="tocid01"> becomes <a id="tocid01" title="Title of this toc item">
If necessary it can then be added to / turned into a proper h tag by the user. In this case also, no problems with nesting or malformed tags.



If adding an h tag above the id is more complicated than it seems (and I'm willing to accept that it is if you say so), then I think there are safer options that still get the job done; at worst, the absolutely fail-safe one being to just add the text inside an html comment immediately before the tag containing the id, whatever it may be, without trying to figure out where it's safe to add an h tag:

Code:
<some random h*, p, or div opening tag which may or may not be broken by inserting an h tag after it>
<!-- Title of the toc item -->
<a id="tocid01"></a>
Bla
</close random tag>
Code:
<!-- Title of the toc item -->
<h id="tocid01">
The point of the plugin would really be just to get the text of the titles from the toc back into the html files where it is useful and can from there be regexed (or at worst copy-pasted) into whatever level of h tag is appropriate. Like I said, it would be one part of a process, much like the "AddIDs" plugin is one step of something larger. No CSS, minimal (potentially none) HTML.
Mister L is offline   Reply With Quote