-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Issue #358 – preventing double nested links #433
Conversation
aidantwoods
commented
Oct 1, 2016
•
edited
Loading
edited
- Add the ability for a parsed element to enforce that the line handler not parse any (immediate) child elements of a specified type.
- Use 1. to allow parsed Link elements to tell the line handler not to parse any child Links or Urls where they are immediate children.
1. Add the ability for a parsed element to enforce that the line handler not parse any (immediate) child elements of a specified type. 2. Use 1. to allow parsed Url elements to tell the line handler not to parse any child Links or Urls where they are immediate children.
If we like 1. as a feature, then I can probably extend the functionality such that (disallowed) nesting can be asserted past a depth of one. i.e. So although this PR fixes the original issue, cases such as:
|
I've built on the functionality of feature 1. in the previous commit to allow non nestables to be asserted indefinitely, or to a specified depth.
This commit serves to add comments detailing parts of the new functionality, and to adjust syntax preferences to match that of the surrounding document. The commit title also now reflects the most significant change made.
@PhrozenByte @erusev any thoughts on the latest changes in this PR? Just noticed another duplicate issue (#432) report popped up for this right before my PR, so looks like this fix is a much needed update |
All in all: Looks great to me! 👍 However, I don't see a use case for specifying a maximum depth for non nestable types. I suggest removing the "array syntax" (i.e. |
Removed granularity controls – elements are assumed to be non nestable indefinitely once declared.
@PhrozenByte That makes sense to me! I've removed it for now, but if it's ever useful then it's easy to re-add if it's ever needed (and forward compatible with the current string syntax etc..) It does simplify the code considerably not having the max depth and mixed syntax ;-) |
{ | ||
$Inline['element']['non_nestables'][] = $non_nestable; | ||
} | ||
$Inline['element']['non_nestables'][] = $non_nestable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about $Inline['element']['non_nestables'] = array_merge($Inline['element']['non_nestables'], $non_nestable);
instead of the foreach
(foreach
is slightly slower btw, however, not to such an extent that it makes any difference)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PhrozenByte I did consider that, though there is no guarantee that the $Inline['element']['non_nestables']
will exist – so the code suffers a little for readability with that added check IMO. Though I appreciate that's a subjective decision, so I'm happy to favour array_merge
if you disagree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, didn't think about that. I agree that adding another check doesn't improve readability, so it's probably best to keep it the way you did 😃
@@ -1003,6 +1003,13 @@ public function line($text) | |||
|
|||
foreach ($this->InlineTypes[$marker] as $inlineType) | |||
{ | |||
# check to see if the current inline type is nestable in the current context | |||
|
|||
if (in_array($inlineType, $non_nestables)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about if (!empty($non_nestables) && in_array($inlineType, $non_nestables))
? in_array()
really is very expensive, even with empty arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds sensible, I'll commit that change when I get a sec :)
Check if array is empty to shave some performance hits in the case than no non nestables are present.
@PhrozenByte I think that's everything in the latest commit? |
Yes, perfect 👍 |
@erusev guessing as before, you'll want camel casing instead of ' |
Yes, pls.
|
@erusev almost – it would be This is because it's built to allow multiple types to be disallowed, (including where multiple non nestables are aggregated over nested elements with different non nestable conditions). So |
Swap `under_scores` for `camelCasing`
Right, well, then there might be a better name for the parameter. Non nestables seems to scary of a word for a parameter that just lists the types that the method should skip. |
@erusev perhaps, any suggestions? 'skipInlineTypes', 'ignoredInlineTypes'? |
Something like this. Let me have a better look at the code later next week and I might come up with some ideas. |
Any chance to merge this PR ? |
@hatrena Sure, I'll try to review it by the end of the month. |