Closed sogaiu closed 3 years ago
Added a commit to check for name collisions and if detected, respond by constructing a name that has not been used already.
There is now a table that stores names along with corresponding integer counts.
The integer is used as a basis for a new suffix for the id in case of collisions. Each time a collision is detected, the integer in the table is incremented.
Also, instead of stripping inner space characters, they are replaced with "-". Leading and trailing space characters are trimmed.
I don't understand how mendoza works well enough to know whether this table needs to be wiped from time-to-time.
Now using def
instead of var
.
Thanks @pyrmont :)
It looks ok to me, I will try this version of mendoza on my project, hopefuly today, and report back.
@pepe Thanks for taking a look!
Looking forward to hearing back -- whatever you find :)
Thanks for trying and reporting :+1:
The current implementation doesn't consider the possibility (apart from the space character and what trim handles) that there might be some characters in the header text that shouldn't live in an attribute.
Allegedly the only character one needs to be concerned about is the space character: https://mathiasbynens.be/notes/html5-id-class
I don't know whether this is true in practice.
Any opinions?
Well, that was my only concern too, cause the first id it generated was "What?" :-). But I would take it from the linked article, that it is OK.
I hope so too :)
Thanks for taking a look!
I like this, this is a useful feature and we can definitely add it. While the collision resolution isn't perfect it looks good enough to start.
@bakpakin Curious about what's problematic for the collision resolution. Any hints?
As I don't really understand what can end up in content
, I wondered if these lines were missing some cases: https://github.com/sogaiu/mendoza/blob/f84e0ea98674a5eb938d98afcd7902766c0bc970/mendoza/markup.janet#L78-L79
In any case, looking forward to ids showing up :)
This is an initial sketch of providing an id attribute to headers that originate as markdown-ish things (i.e. 1-6
#
s).It targets only initial string elements of the
content
parameter forcaph
: https://github.com/bakpakin/mendoza/blob/2c0010a3e84cab860651da8b961410a2f84abaf4/mendoza/markup.janet#L73All it does is strip occurences of the space character. Thus it's true that there is potential for collisions.
If that's a concern worth addressing, perhaps there could be a table that's populated and checked for collisions. For a collision, possibly some string can be appended to the checked name and the result could be checked against the table (possibly leading to further checks and appending -- but this should terminate at some point).
I'm not so sure collisions would be that frequent. Though perhaps there are some cases where people want to use the same header names within a page or that space removal could lead to collisions. For the latter case, perhaps that makes replacing inner spaces with
-
characters a better alternative.An alternative approach to trying to come up with non-colliding names automatically might be to halt processing and inform the user that there was a name collision -- though it seems this would also require something like a table.