Skip to content

Commit

Permalink
1.8.01 patch
Browse files Browse the repository at this point in the history
  • Loading branch information
KosmosisDire committed Mar 6, 2024
1 parent 5dcb8b3 commit 1c8c969
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 71 deletions.
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "webpage-html-export",
"name": "Webpage HTML Export",
"version": "1.8.0",
"version": "1.8.1-2b",
"minAppVersion": "1.4.0",
"description": "Export full websites or html documents from single files, canvas pages, or whole vaults. Similar to obsidian's publish or digital garden, but with direct access to the exported HTML. Focuses on flexibility, features, and style parity.",
"author": "Nathan George",
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"id": "webpage-html-export",
"name": "Webpage HTML Export",
"version": "1.8.0",
"version": "1.8.01",
"minAppVersion": "1.4.0",
"description": "Export html from single files, canvas pages, or whole vaults. Direct access to the exported HTML files allows you to publish your digital garden anywhere. Focuses on flexibility, features, and style parity.",
"author": "Nathan George",
"authorUrl": "https://github.com/KosmosisDire/obsidian-webpage-export",
"isDesktopOnly": true,
"fundingUrl": "https://www.buymeacoffee.com/nathangeorge",
"updateNote": ""
"updateNote": "This is a quick patch to fix the style issue\ncaused by the obsidian 1.5.8 update.\nIt is not newer than the current 1.8.1 beta."
}
92 changes: 25 additions & 67 deletions scripts/html-generation/assets/obsidian-styles.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { Asset, AssetType, InlinePolicy, LoadMethod, Mutability } from "./asset";
import { SettingsPage } from "scripts/settings/settings";
import { ExportLog } from "../render-log";
import obsidianStyleOverrides from "assets/obsidian-styles.txt.css";
import { MarkdownWebpageRendererAPIOptions } from "scripts/api-options";
import { Asset, AssetType, InlinePolicy, LoadMethod, Mutability } from "./asset.js";
import { MarkdownWebpageRendererAPIOptions } from "scripts/api-options.js";

export class ObsidianStyles extends Asset
{
public content: string = "";

public content: string = "";
constructor()
{
super("obsidian.css", "", AssetType.Style, InlinePolicy.AutoHead, true, Mutability.Dynamic, LoadMethod.Default, 10);
}

public static stylesFilter =
["workspace-", "cm-", "ghost", "leaf", "CodeMirror",
public static readonly stylesFilter =
["workspace-", "cm-", "cm6", "ghost", "leaf", "CodeMirror",
"@media", "pdf", "xfa", "annotation", "@keyframes",
"load", "@-webkit", "setting", "filter", "decorator",
"dictionary", "status", "windows", "titlebar", "source",
Expand All @@ -25,82 +22,43 @@ export class ObsidianStyles extends Asset
"progress", "native", "aria", "tooltip",
"drop", "sidebar", "mod-windows", "is-frameless",
"is-hidden-frameless", "obsidian-app", "show-view-header",
"is-maximized", "is-translucent", "community"];

public static stylesKeep = ["scrollbar", "input[type", "table", "markdown-rendered", "css-settings-manager", "inline-embed", "background", "token"];

removeSelectors(css: string, containing: string): string
{
let regex = new RegExp(`([\w :*+~\\-\\.\\>\\[\\]()"=]*${containing}[\\w\\s:*+~\\-\\.\\>\\[\\]()"=]+)(,|{)`, "gm");
let toRemove = [...css.matchAll(regex)];
for (let match of toRemove)
{
css = css.replace(match[1], "");
}
css = css.trim();
return css;
}
"is-maximized", "is-translucent", "community", "Layer"];

public static readonly stylesKeep = ["tree", "scrollbar", "input[type", "table", "markdown-rendered", "css-settings-manager", "inline-embed", "background", "token"];

override async load(options: MarkdownWebpageRendererAPIOptions)
{
this.content = "";

let appSheet = document.styleSheets[1];
let stylesheets = document.styleSheets;
for (let i = 0; i < stylesheets.length; i++)
let stylesheets = Array.from(document.styleSheets);
for (const element of stylesheets)
{
if (stylesheets[i].href && stylesheets[i].href?.includes("app.css"))
if (element.href && element.href?.includes("app.css"))
{
appSheet = stylesheets[i];
appSheet = element;
break;
}
}

this.content += obsidianStyleOverrides;

for (let i = 0; i < appSheet.cssRules.length; i++)
{
let rule = appSheet.cssRules[i];
if (rule)
{
let skip = false;
let cssText = rule.cssText;
let selector = cssText.split("{")[0];
let cssRules = Array.from(appSheet.cssRules);
for (const element of cssRules)
{
let rule = element;
let selectors = rule.cssText.split("{")[0].split(",");
let declarations = rule.cssText.split("{")[1].split("}")[0].split(";");

for (let keep of ObsidianStyles.stylesKeep)
{
if (!selector.includes(keep))
{
// filter out certain unused styles to reduce file size
for (let filter of ObsidianStyles.stylesFilter)
{
if (selector.includes(filter))
{
skip = true;
break;
}
}
}
else
{
skip = false;
break;
}
}
selectors = selectors.map((selector) => selector.trim());
selectors = selectors.filter((selector) => ObsidianStyles.stylesKeep.some((keep) => selector.includes(keep)) || !ObsidianStyles.stylesFilter.some((filter) => selector.includes(filter)));

if (skip) continue;

cssText = this.removeSelectors(cssText, "\\.cm-");
if(cssText.startsWith("{")) continue; // skip empty rules
if (selectors.length == 0)
continue;

cssText += "\n";

this.content += cssText;
}
}
let newRule = selectors.join(", ") + " { " + declarations.join("; ") + " }";
this.content += newRule + "\n";
}

this.modifiedTime = Date.now();
this.content += obsidianStyleOverrides;
await super.load(options);
}
}
2 changes: 1 addition & 1 deletion scripts/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ This feature does not require "File & folder icons" to be enbaled.`);
allowRelative: true,
allowFiles: true,
requireExists: true,
requireExtentions: ["html, htm, txt"]
requireExtentions: ["html", "htm", "txt"]
}),
});

Expand Down

0 comments on commit 1c8c969

Please sign in to comment.