') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Fix baseUrl not working in include src attribute by ang-zeyu · Pull Request #1088 · MarkBind/markbind · GitHub
Skip to content

Fix baseUrl not working in include src attribute - #1088

Merged
yamgent merged 1 commit into
MarkBind:masterfrom
ang-zeyu:fix-base-url
Mar 29, 2020
Merged

Fix baseUrl not working in include src attribute#1088
yamgent merged 1 commit into
MarkBind:masterfrom
ang-zeyu:fix-base-url

Conversation

@ang-zeyu

@ang-zeyuang-zeyu commented Mar 4, 2020

Copy link
Copy Markdown
Contributor

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [x] Bug fix

Fixes#928
Requires #1087 ( removal of _rebaseReferenceForStaticIncludes ( neccessary ) and adding getParentSiteAbsolutePath ( standardisation ) ) merged

What is the rationale for this request?
To fix the case that the user wants to use {{baseUrl}} inside the src attribute of a <include/panel>.

What changes did you make? (Give an overview)

  • When resolving the source file path of the included path, in addition to checking whether the source file is url, we check if the src has a {{\s*baseUrl\s*}}[/\\] regex.
    If so, we recalculate the include source file path using the baseUrl of the current working file.
  • Added some functional tests to check for such cases
  • Added Markbind.unwrapIncludeSrc to the dynamic include build chain since it was missed before and my functional tests require it ( otherwise data-included-from would have my system's absolute file path, causing tests to fail )

Provide some example code that this change will affect:

...
if(baseUrlRegex.test(includePath)){// The baseUrl has not been resolved during pre-processing, but we need the source file pathconstparentSitePath=urlUtils.getParentSiteAbsolutePath(context.cwf,config.rootPath,config.baseUrlMap);filePath=path.resolve(parentSitePath,includePath.replace(baseUrlRegex,''));}else{
...

Is there anything you'd like reviewers to focus on?
na

Testing instructions:

  • npm run test should pass
  • 2103 site should differ for **._include_.html files as Markbind.unwrapIncludeSrc was added. ( the wrapper div and spans with data-included-from should be deleted. )

Proposed commit message: (wrap lines at 72 characters)
Fix baseUrl not working in include src attribute

While pre-processing includes or panels, we have not yet resolved
the baseUrl of the src attribute.
This causes markbind to fail in finding the source file, since baseUrl
remains in the src attribute.

Let’s resolve the baseUrl for such cases first, allowing the user to use
the baseUrl attribute in include and panel src attributes.

@ang-zeyu
ang-zeyuforce-pushed the fix-base-url branch 4 times, most recently from 2a67704 to 9165b20CompareMarch 9, 2020 10:30
@ang-zeyu

ang-zeyu commented Mar 15, 2020

Copy link
Copy Markdown
ContributorAuthor

Can be reviewed now that #1087 has been merged!

@ang-zeyu
ang-zeyuforce-pushed the fix-base-url branch 4 times, most recently from 900881a to 0972aefCompareMarch 22, 2020 05:31
While pre-processing includes or panels, we have not yet resolved
the baseUrl of the src attribute.
This causes markbind to fail in finding the source file, since baseUrl
remains in the src attribute.
Let’s resolve the baseUrl for such cases first, allowing the user to use
the baseUrl attribute in include and panel src attributes.
@yamgentyamgent added this to the v2.12.1 milestone Mar 29, 2020
@yamgent
yamgent merged commit 13dc7b7 into MarkBind:masterMar 29, 2020
marvinchin pushed a commit that referenced this pull request Apr 10, 2020
While pre-processing includes or panels, we have not yet resolved
the baseUrl of the src attribute.
This causes markbind to fail in finding the source file, since baseUrl
remains in the src attribute.
Let’s resolve the baseUrl for such cases first, allowing the user to use
the baseUrl attribute in include and panel src attributes.
ang-zeyu added a commit to ang-zeyu/markbind that referenced this pull request Jun 10, 2020
BaseUrl processing is done in a separate stage involving repeated and
recursive parsing / rendering of the content.
This decreases cohesiveness of variable processing, and also
performance due to the repeated parsing and rendering.
It also necessitates edge-case solutions such as that in MarkBind#1088 when we
need to resolve the baseUrl before the resolveBaseUrl stage has been
reached.
With a framework for variable processing now, let's move baseUrl
processing into it, solving the above said problems.
Furthermore, rendering of other variables containing html is dependent
on the extra htmlparser call in resolveBaseUrl.
Let's formally remove the need for this by using only the unescaped
nunjucks environment to render variables.
ang-zeyu added a commit to ang-zeyu/markbind that referenced this pull request Jun 10, 2020
BaseUrl processing is done in a separate stage involving repeated and
recursive parsing / rendering of the content.
This decreases cohesiveness of variable processing, and also
performance due to the repeated parsing and rendering.
It also necessitates edge-case solutions such as that in MarkBind#1088 when we
need to resolve the baseUrl before the resolveBaseUrl stage has been
reached.
With a framework for variable processing now, let's move baseUrl
processing into it, solving the above said problems.
Furthermore, rendering of other variables containing html is dependent
on the extra htmlparser call in resolveBaseUrl.
Let's formally remove the need for this by using only the unescaped
nunjucks environment to render variables.
ang-zeyu added a commit to ang-zeyu/markbind that referenced this pull request Jun 13, 2020
BaseUrl processing is done in a separate stage involving repeated and
recursive parsing / rendering of the content.
This decreases cohesiveness of variable processing, and also
performance due to the repeated parsing and rendering.
It also necessitates edge-case solutions such as that in MarkBind#1088 when we
need to resolve the baseUrl before the resolveBaseUrl stage has been
reached.
With a framework for variable processing now, let's move baseUrl
processing into it, solving the above said problems.
Furthermore, rendering of other variables containing html is dependent
on the extra htmlparser call in resolveBaseUrl.
Let's formally remove the need for this by using only the unescaped
nunjucks environment to render variables.
ang-zeyu added a commit to ang-zeyu/markbind that referenced this pull request Jun 13, 2020
BaseUrl processing is done in a separate stage involving repeated and
recursive parsing / rendering of the content.
This decreases cohesiveness of variable processing, and also
performance due to the repeated parsing and rendering.
It also necessitates edge-case solutions such as that in MarkBind#1088 when we
need to resolve the baseUrl before the resolveBaseUrl stage has been
reached.
With a framework for variable processing now, let's move baseUrl
processing into it, solving the above said problems.
Furthermore, rendering of other variables containing html is dependent
on the extra htmlparser call in resolveBaseUrl.
Let's formally remove the need for this by using only the unescaped
nunjucks environment to render variables.
ang-zeyu added a commit to ang-zeyu/markbind that referenced this pull request Jun 22, 2020
BaseUrl processing is done in a separate stage involving repeated and
recursive parsing / rendering of the content.
This decreases cohesiveness of variable processing, and also
performance due to the repeated parsing and rendering.
It also necessitates edge-case solutions such as that in MarkBind#1088 when we
need to resolve the baseUrl before the resolveBaseUrl stage has been
reached.
With a framework for variable processing now, let's move baseUrl
processing into it, solving the above said problems.
Furthermore, rendering of other variables containing html is dependent
on the extra htmlparser call in resolveBaseUrl.
Let's formally remove the need for this by using only the unescaped
nunjucks environment to render variables.
ang-zeyu added a commit to ang-zeyu/markbind that referenced this pull request Jun 26, 2020
BaseUrl processing is done in a separate stage involving repeated and
recursive parsing / rendering of the content.
This decreases cohesiveness of variable processing, and also
performance due to the repeated parsing and rendering.
It also necessitates edge-case solutions such as that in MarkBind#1088 when we
need to resolve the baseUrl before the resolveBaseUrl stage has been
reached.
With a framework for variable processing now, let's move baseUrl
processing into it, solving the above said problems.
Furthermore, rendering of other variables containing html is dependent
on the extra htmlparser call in resolveBaseUrl.
Let's formally remove the need for this by using only the unescaped
nunjucks environment to render variables.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

{{baseUrl}} in boilerplates is not behaving as an absolute URL

2 participants

@ang-zeyu@yamgent