Skip to content

Instantly share code, notes, and snippets.

View fantasticit's full-sized avatar
🤖

fantasticit fantasticit

🤖
View GitHub Profile
@johanobergman
johanobergman / migrate-to-tiptap-format.js
Last active July 19, 2024 16:54
Migrate html to a more TipTap-friendly structure
/**
* Modifies legacy html to match TipTap document structure,
* without losing content.
*
* Images in paragraphs, links with images inside,
* links not in paragraphs and YouTube videos
* are taken care of.
*
* Images are assumed to be configured as blocks in TipTap.
@BrianHung
BrianHung / codemirror-syntax-highlight.ts
Last active March 19, 2024 19:53
ProseMirror CodeBlock Syntax Highlighting using CM6
import {LanguageDescription, LanguageSupport} from "@codemirror/language"
import {languages} from "@codemirror/language-data"
import {highlightTree} from "@codemirror/highlight"
import {highlightStyle} from "./highlight-style"
export function syntaxHighlight(text: string, support: LanguageSupport, callback: (token: {text: string; style: string; from: number; to: number}) => void, options = {match: highlightStyle.match}) {
let pos = 0;
let tree = support.language.parseString(text);
highlightTree(tree, options.match, (from, to, classes) => {
from > pos && callback({text: text.slice(pos, from), style: null, from: pos, to: from});
@jose-mdz
jose-mdz / README.md
Last active February 28, 2026 08:40
Orthogonal Diagram Connector

Orthogonal Connectors

This algorithm returns the points that form an orthogonal path between two rectangles.

How to Use

// Define shapes
const shapeA = {left: 50,  top: 50, width: 100, height: 100};
const shapeB = {left: 200, top: 200, width: 50, height: 100};
@wyl8899
wyl8899 / spacing.ts
Created September 29, 2020 17:48
JavaScript 实现中英文空格 - Implementation
/* Partial implementation from https://zhuanlan.zhihu.com/p/33612593 */
import _ from 'lodash';
/* 标点 */
const punctuationRegex = /\p{Punctuation}/u;
/* 空格 */
const spaceRegex = /\p{Separator}/u;
/* CJK 字符,中日韩 */
const cjkRegex = /\p{Script=Han}|\p{Script=Katakana}|\p{Script=Hiragana}|\p{Script=Hangul}/u;
@BrianHung
BrianHung / MathBlock.css
Last active February 19, 2025 09:20
MathBlock NodeView for TipTap
.ProseMirror .MathBlock pre {
background: var(--default-back);
color: rgb(var(--default-font));
font-size: 0.8em;
display: flex;
padding: 1em;
}
.ProseMirror .MathBlock {
display: flex;
@BrianHung
BrianHung / Math.css
Last active October 30, 2022 04:58
Math NodeView for TipTap
.ProseMirror .Math {
display: contents;
}
.ProseMirror .Math .katex-editor {
display: inline;
}
.ProseMirror .Math .katex-render .katex {
font-size: 1em;
@dcondrey
dcondrey / savetoDoc.js
Created August 5, 2017 22:29
Export an HTML element to Microsoft Word with CSS styles to set page orientation and paper size.
/* HTML to Microsoft Word Export
* This code demonstrates how to export an html element to Microsoft Word
* with CSS styles to set page orientation and paper size.
* Tested with Word 2010, 2013 and FireFox, Chrome, Opera, IE10-11
* Fails in legacy browsers (IE<10) that lack window.Blob object
*/
function saveDoc() {
if (!window.Blob) {
alert('Your legacy browser does not support this action.');
@evantahler
evantahler / buildSitemap.js
Last active December 17, 2020 16:35
35 lines to build a sitemap for next.js projects
#! /usr/bin/env node
// I am ./bin/buildSitemap.js
const path = require('path')
const glob = require('glob')
const fs = require('fs')
const SITE_ROOT = process.env.SITE_ROOT || 'https://www.actionherojs.com'
const SOURCE = process.env.SOURCE || path.join(__dirname, '..', 'pages', '/**/*.js')
const DESTINATION = process.env.DESTINATION || path.join(__dirname, '..', 'static', 'sitemap.xml')
@ThariqS
ThariqS / gist:72cb138d33e7bcfd15d0440cc4bd555a
Created January 16, 2017 18:04
Prosemirror Selection Plugin
import {Decoration, DecorationSet} from "prosemirror-view";
import {Plugin} from 'prosemirror-state';
const SelectPlugin = new Plugin({
state: {
init(config, instance) {
return { deco: DecorationSet.empty };
},
apply(transaction, state, prevEditorState, editorState) {
@paulirish
paulirish / what-forces-layout.md
Last active March 15, 2026 16:37
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent