Skip to content

Commit

Permalink
Merge pull request #1200 from Patternslib/update-dev
Browse files Browse the repository at this point in the history
Update dev
  • Loading branch information
thet authored Aug 16, 2024
2 parents 4d58617 + a413e26 commit 141f9aa
Show file tree
Hide file tree
Showing 6 changed files with 1,742 additions and 2,485 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'
cache: 'yarn'
- run: |
make install
Expand Down
4 changes: 2 additions & 2 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/_/husky.sh"

#npx yarn commitlint --edit $1
npx yarn commitlint --edit $1
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
"tippy.js": "^6.3.7"
},
"devDependencies": {
"@patternslib/dev": "^3.5.3",
"@patternslib/dev": "^3.6.0",
"@patternslib/pat-content-mirror": "^3.0.0",
"@patternslib/pat-doclock": "^3.0.0",
"@patternslib/pat-shopping-cart": "^3.0.0",
"@patternslib/pat-sortable-table": "^3.1.0",
"@patternslib/pat-tiptap": "^4.9.2",
"@patternslib/pat-upload": "^3.1.1",
"copy-webpack-plugin": "^11.0.0",
"copy-webpack-plugin": "^12.0.2",
"css.escape": "^1.5.1",
"modernizr": "^3.13.0",
"modernizr": "^3.13.1",
"pegjs": "0.11.0-master.b7b87ea"
},
"resolutions": {
Expand Down
43 changes: 20 additions & 23 deletions src/pat/inject/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,12 +831,12 @@ const inject = {
},

_rebaseAttrs: {
A: "href",
FORM: "action",
IMG: "data-pat-inject-rebase-src",
OBJECT: "data",
SOURCE: "data-pat-inject-rebase-src",
VIDEO: "data-pat-inject-rebase-src",
a: "href",
form: "action",
img: "data-pat-inject-rebase-src",
object: "data",
source: "data-pat-inject-rebase-src",
video: "data-pat-inject-rebase-src",
},

_rebaseOptions: {
Expand All @@ -860,16 +860,16 @@ const inject = {
// Special case, source is none
return "";
}
const $page = $(
html.replace(/(\s)(src\s*)=/gi, '$1src="" data-pat-inject-rebase-$2=').trim()
)
.wrapAll("<div>")
.parent();

$page.find(Object.keys(this._rebaseAttrs).join(",")).each((idx, el_) => {
const $el_ = $(el_);
const attrName = this._rebaseAttrs[el_.tagName];
let value = $el_.attr(attrName);
// Create temporary DOM node and store the html contents on it where
// the original src attribute is kept.
const node = document.createElement("div");
node.innerHTML = html.replace(/(\s)(src\s*)=/gi, '$1src="" data-pat-inject-rebase-$2=').trim();

const selector = Object.keys(this._rebaseAttrs).join(",");
for (const el_ of node.querySelectorAll(selector)) {
const attr = this._rebaseAttrs[el_.tagName.toLowerCase()];
let value = el_.getAttribute(attr);

if (
value &&
Expand All @@ -884,15 +884,12 @@ const inject = {
value.slice(0, 11) !== "javascript:"
) {
value = this._rebaseURL(base, value);
$el_.attr(attrName, value);
el_.setAttribute(attr, value);
}
});
}

for (const [pattern_name, opts] of Object.entries(this._rebaseOptions)) {
for (const el_ of dom.querySelectorAllAndMe(
$page[0],
`[data-pat-${pattern_name}]`
)) {
for (const el_ of node.querySelectorAll(`[data-pat-${pattern_name}]`)) {
const pattern = registry.patterns?.[pattern_name];
const pattern_parser = pattern?.parser;
if (!pattern_parser) {
Expand Down Expand Up @@ -924,8 +921,8 @@ const inject = {
}
}

return $page
.html()
return node
.innerHTML
.replace(/src="" data-pat-inject-rebase-/g, "")
.trim();
},
Expand Down
4 changes: 2 additions & 2 deletions src/pat/inject/inject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ describe("pat-inject", function () {
);
});

it("5.4 - Element without link attribute", function () {
it("5.4 - Anchor element without href attribute", function () {
var spy_rebaseURL = jest.spyOn(pattern, "_rebaseURL");
expect(pattern._rebaseHTML("base", "<a>This is a test</a>")).toBe(
"<a>This is a test</a>"
Expand All @@ -354,7 +354,7 @@ describe("pat-inject", function () {
spy_rebaseURL.mockRestore();
});

it("5.5 - Element with link attribute", function () {
it("5.5 - Anchor element with href attribute", function () {
expect(
pattern._rebaseHTML(
"http://example.com/test/",
Expand Down
Loading

0 comments on commit 141f9aa

Please sign in to comment.