Skip to content

Commit

Permalink
Add better support for ignoring query string replacement
Browse files Browse the repository at this point in the history
Instead of skipping CODE or code blocks in the DOM, any node (or descendant of a node) with the no-query-replace class will not get evaluated for query-param substitution

Updated index.adoc to test this and demonstrate in some common cases how this would work (including code blocks)
  • Loading branch information
hatmarch committed Jul 12, 2021
1 parent 574a347 commit de76142
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
26 changes: 26 additions & 0 deletions preview-src/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Author Name
:!example-caption:
:!table-caption:
:page-pagination:
:USER: %USER%

image:multirepo-ssg.svg[Multirepo SSG,200,float=right]
Platonem complectitur mediocritatem ea eos.
Expand All @@ -31,6 +32,31 @@ I like %COLOR% color

Here is a link:index.html?USER=%USER%#liber-recusabo[link^] containing a query string item that should open to "Liber recusabo" in a new window

[#query-string-replacement-testing]
== Query String Replacement Testing

_If the `USER` query string has been set in the URL, then you should see it replaced (or not) below according to the text_

[.console-output]
[source,bash,subs="+macros,+attributes"]
----
This should show the USER substitution: {USER}
----

This should also show the USER substitution: `%USER%`

[.no-query-replace]
[.console-output]
[source,bash,noquery,subs="+macros,+attributes"]
----
This should not: pass:[%USER%]
----

And this also should not: [.no-query-replace]`%USER%`

You should see USER replacement here: %USER% but not here: [.no-query-replace]#%USER%#


== Cu solet

Nominavi luptatum eos, an vim hinc philosophia intellegebat.
Expand Down
3 changes: 3 additions & 0 deletions preview-src/ui-model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ page:
- content: Link Testing
url: '/xyz/5.2/index.html#link-testing'
urlType: internal
- content: Query String Replacement Testing
url: '/xyz/5.2/index.html#query-string-replacement-testing'
urlType: internal
- content: Cu Solet
url: '/xyz/5.2/index.html#cu-solet'
urlType: internal
Expand Down
10 changes: 4 additions & 6 deletions src/js/07-userparams-behaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ document.addEventListener('DOMContentLoaded', function () {
// refreshing links

function replaceParamsInNodes (node, key, value) {
if (node.parentElement) {
//console.log('Parent element %s', node.parentElement.nodeName)
if (node.parentElement.nodeName === 'code' ||
node.parentElement.nodeName === 'CODE') {
return
}
// Don't descend into any nodes that are children of the no-query-replace class
if ((typeof node.classList !== 'undefined') && (node.classList.contains('no-query-replace'))) {
return
}

if (node.nodeType === 3) {
var text = node.data
node.data = applyPattern(text, key, value)
Expand Down

0 comments on commit de76142

Please sign in to comment.