Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hexo-filter-tikzjax

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hexo-filter-tikzjax - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

8

dist/index.js

@@ -5,3 +5,2 @@ "use strict";

const insert_svg_1 = require("./insert-svg");
const prepend_css_1 = require("./prepend-css");
const common_1 = require("./common");

@@ -13,5 +12,4 @@ // Load plugin config.

hexo.extend.filter.register('before_post_render', render_tikzjax_1.renderTikzjax, 1);
// Insert generated SVGs into HTML of the post as inline tags.
hexo.extend.filter.register('after_post_render', insert_svg_1.insertSvg);
// Add CSS to pages which contain TikZ graphics.
hexo.extend.filter.register('after_render:html', prepend_css_1.prependCss);
// Insert generated SVGs into HTML of the post/page as inline tags.
// Also add CSS to pages which contain TikZ graphs.
hexo.extend.filter.register('after_render:html', insert_svg_1.insertSvg);
import type Hexo from 'hexo';
import { PostData } from './common';
import { TemplateLocals } from './common';
/**

@@ -9,4 +9,7 @@ * Insert generated SVGs into HTML of the post as inline tags.

* But insert SVGs into Markdown source will cause problems, so we wait until the Markdown
* source is rendered into HTML, then insert SVGs into HTML (in `after_post_render`).
* source is rendered into HTML, then insert SVGs into HTML (in `after_render:html`).
*
* Since we need to process archive/tags/categories pages too, if they contains posts which
* have TikZ graphs in it, the `after_post_render` filter is not sufficient.
*/
export declare function insertSvg(this: Hexo, data: PostData): PostData | void;
export declare function insertSvg(this: Hexo, html: string, locals: TemplateLocals): string | void;

@@ -11,12 +11,22 @@ "use strict";

* But insert SVGs into Markdown source will cause problems, so we wait until the Markdown
* source is rendered into HTML, then insert SVGs into HTML (in `after_post_render`).
* source is rendered into HTML, then insert SVGs into HTML (in `after_render:html`).
*
* Since we need to process archive/tags/categories pages too, if they contains posts which
* have TikZ graphs in it, the `after_post_render` filter is not sufficient.
*/
function insertSvg(data) {
function insertSvg(html, locals) {
const config = this.config.tikzjax;
if (!data.tikzjax && !config.every_page) {
const page = locals.page;
const indexContains = page.__index && page.posts.toArray().find((post) => post.tikzjax);
// Only process if a post contains TikZ, or it's an index page and one of the posts contains TikZ.
if (!page.tikzjax && !config.every_page && !indexContains) {
return;
}
// Prepend CSS for TikZJax.
html = html.replace(/<head>(?!<\/head>).+?<\/head>/s, (str) => str.replace('</head>', `<link rel="stylesheet" type="text/css" href="${config.font_css_url}" />` +
(config.inline_style ? `<style>${config.inline_style}</style>` : '') +
'</head>'));
// Find all TikZ placeholders inserted by `renderTikzjax`.
const regex = /<!-- tikzjax-placeholder-(\w+?) -->/g;
const matches = data.content.matchAll(regex);
const matches = html.matchAll(regex);
const debug = (...args) => this.log.debug('[hexo-filter-tikzjax]', ...args);

@@ -31,3 +41,3 @@ for (const match of matches) {

if (svg) {
data.content = data.content.replace(match[0], `<p><span class="tikzjax">${svg}</span></p>`);
html = html.replace(match[0], `<p><span class="tikzjax">${svg}</span></p>`);
debug('SVG inserted!', hash);

@@ -39,4 +49,4 @@ }

}
return data;
return html;
}
exports.insertSvg = insertSvg;
{
"name": "hexo-filter-tikzjax",
"description": "Server side PGF/TikZ renderer plugin for Hexo.",
"version": "1.0.0",
"version": "1.0.1",
"author": "prin <hi@prin.studio>",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -92,3 +92,3 @@ # hexo-filter-tikzjax

![01-post-render](docs/01-post-render.png)
![01-post-render](https://github.com/prinsss/hexo-filter-tikzjax/raw/main/docs/01-post-render.png)

@@ -95,0 +95,0 @@ ## License

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc