mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
Make NYTimes more stable, add rewriting for <image> tags.
This commit is contained in:
parent
dc80bf1170
commit
b6eb174bfe
2 changed files with 17 additions and 14 deletions
|
@ -77,16 +77,17 @@ export default function (client: ScramjetClient, self: Self) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!self.event) {
|
||||
Object.defineProperty(self, "event", {
|
||||
get() {
|
||||
return argArray[0];
|
||||
},
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
|
||||
let rv = Reflect.apply(target, thisArg, argArray);
|
||||
const rv = Reflect.apply(target, thisArg, argArray);
|
||||
|
||||
delete self.event;
|
||||
|
||||
return rv;
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ElementType, Parser } from "htmlparser2";
|
||||
import { ChildNode, DomHandler, Element, Node, Text } from "domhandler";
|
||||
import { ChildNode, DomHandler, Element } from "domhandler";
|
||||
import render from "dom-serializer";
|
||||
import { URLMeta, encodeUrl } from "./url";
|
||||
import { rewriteCss } from "./css";
|
||||
|
@ -68,10 +68,10 @@ export function rewriteHtml(
|
|||
return render(handler.root);
|
||||
}
|
||||
|
||||
type ParseState = {
|
||||
base: string;
|
||||
origin?: URL;
|
||||
};
|
||||
// type ParseState = {
|
||||
// base: string;
|
||||
// origin?: URL;
|
||||
// };
|
||||
|
||||
export function unrewriteHtml(html: string) {
|
||||
const handler = new DomHandler((err, dom) => dom);
|
||||
|
@ -103,7 +103,7 @@ export function unrewriteHtml(html: string) {
|
|||
}
|
||||
|
||||
export const htmlRules: {
|
||||
[key: string]: "*" | string[] | Function;
|
||||
[key: string]: "*" | string[] | ((...any: any[]) => string | null);
|
||||
fn: (value: string, meta: URLMeta, cookieStore: CookieStore) => string | null;
|
||||
}[] = [
|
||||
{
|
||||
|
@ -116,6 +116,7 @@ export const htmlRules: {
|
|||
"embed",
|
||||
"script",
|
||||
"img",
|
||||
"image",
|
||||
"iframe",
|
||||
"source",
|
||||
"video",
|
||||
|
@ -128,6 +129,7 @@ export const htmlRules: {
|
|||
action: ["form"],
|
||||
formaction: ["button", "input", "textarea", "submit"],
|
||||
poster: ["video"],
|
||||
"xlink:href": ["image"],
|
||||
},
|
||||
{
|
||||
fn: () => null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue