-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
refactor: rewrite getAndRemoveConfig(str) function #2472
base: develop
Are you sure you want to change the base?
Conversation
Reactor getAndRemoveConfig function to a generic lexer instead of a complex regex. Correctly the behavior and only resolve valid configs. Warning invalid configs also.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@Koooooo-7 --
|
Thanks very much @Koooooo-7 for this! I've put my original CodeSandbox example online with your Docsify Preview build and @jhildenbiddle examples to help with testing - looking good so far 🙂 https://paulhibbitts.github.io/docsify-v5-preview/#/test-3 |
It will be resolve to
Cos the
I see, will refactor to retrieve the closest pre/next
Gotcha. Will update to clean the whole |
Hi @jhildenbiddle ---
And I add more test cases and comments on those cases we discussed. |
Thanks so much @Koooooo-7 , this is going to be a really nice improvement 🙂 I've updated my online Docsify Preview build with your latest Preview and things look good! https://paulhibbitts.github.io/docsify-v5-preview/#/test-3 |
Thx for you live preview for the changes !!! |
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.
Suggestion on this:
- How does this handle multiple attributes when multiple values are provided?
[Text](page.md ':target=_blank :class=foo bar') [Text](page.md ':class=foo bar :target=_blank ')
It will be resolve to
{ target: "_blank", class: foo, class_appened_props: "bar" }
Instead of capturing multiple values using class
and class_appended_props
properties, why not require multiple values to be wrapped in quotes? This seems more natural since it is how attributes and values work in HTML. It will also make it easier to read multiple attribute values because all values are contained in a single property.
For example:
[Text](page.md ':foo :target=_blank :class="bar baz" This is the title')
{
foo: true,
target: "_blank",
class: "bar baz",
title: "This is the title" // links support title attribute in markdown
}
The rules would then be:
- All attributes must start with
:
- Attributes without values are valid (
:foo
) - Quotes are optional for single values (
:target=_blank
or:target="_blank"
) - Quotes are required for multiple attribute values (
:class="bar baz"'
)
The question is then if/how we want to handle stray, unquoted values. Consider the following example:
[Text](page.md ':foo=val1 val2 :bar=val3 val4'). // Missing quotes around multiple values
I would expect this to produce the following:
{
foo: "val1",
bar: "val3",
title: "val4",
}
What happens to val2
?
The easiest thing to do would be to just drop val2
because according to the rules this is neither an attribute (does not start with :
) or an attribute value.
Thoughts?
That would be more clearly. but it brings a breaking change for all the config rules for now. So I choose a compromise way to make it and doesn't breaking anything to get ride of the regex. Besides, the config of docsify is not that consistent.
It is hard to say a data attribute nor a docsify config within a string. If we decided include a breaking change on this. I think we can introduce a docsify config block. e.g.
Then, we have a clear line to distinguish between the docsify part and custom made for markdown owned. |
Makes sense. I didn't realize that the attribute parser is inconsistent across tags. I appreciate trying to not introduce a non-breaking change, but perhaps this is the opportunity make attribute parsing consistent in docsify for all markdown tags that support it. See below...
Can we add something like the proposed "block" of attributes above as a new v5 feature but retain the existing For example, we can drop the [Text](page.md ':[foo target="_blank" class="bar baz"] This is the title') Alternatively, we could use single or double brackets to start/end the pattern which would make it easy for us to parse using [Text](page.md '{foo: true, target: "_blank" class: "bar baz"} This is the title') [Text](page.md '{{foo: true, target: "_blank" class: "bar baz"}} This is the title') If we go this route, I would propose we not allow mixing new and old attribute styles like this: [Text](page.md '{{foo: true, class: "bar baz"}} :target=_blank This is the title') Doing this promotes continued use of the old This seems like a better approach than updating the |
Summary
Reactor
getAndRemoveConfig(str)
function to a generic Lexer instead of a complex regex.Correct current behavior and indicate docsify needs to resolve valid config keys. Warning invalid configs also.
Remove to use a tricky returned
title
as config options.Instead, new
KEY_appened_props
introduced.It will let the config parse as
:KEY=VALUE append_props...
, each config processor can handle its own logicfor the
Value
andappend_props
. e.g.Which can support
multi values
configs of one key such as #2471 .Related issue, if any:
What kind of change does this PR introduce?
Refactor
For any code change,
Does this PR introduce a breaking change?
Yes
No
Tested in the following browsers: