├── .npmrc ├── .eslintignore ├── versions.json ├── .gitignore ├── .editorconfig ├── manifest.json ├── tsconfig.json ├── version-bump.mjs ├── .eslintrc ├── package.json ├── LICENSE ├── esbuild.config.mjs ├── README.md └── main.ts /.npmrc: -------------------------------------------------------------------------------- 1 | tag-version-prefix="" -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | npm node_modules 2 | build -------------------------------------------------------------------------------- /versions.json: -------------------------------------------------------------------------------- 1 | { 2 | "0.1.0": "1.0.0" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # npm 2 | node_modules 3 | package-lock.json 4 | yarn.lock 5 | 6 | # build 7 | main.js 8 | *.js.map 9 | 10 | # obsidian 11 | data.json 12 | 13 | # mac 14 | .DS_STORE -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = tab 9 | indent_size = 4 10 | tab_width = 4 11 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "list-style", 3 | "name": "Ordered List Style", 4 | "version": "0.1.0", 5 | "minAppVersion": "1.0.0", 6 | "description": "Set ordered list style inline in Obsidian.md. Alphabetic lists, roman numeral lists, etc.", 7 | "author": "Eric Rykwalder", 8 | "authorUrl": "https://github.com/erykwalder/obsidian-list-style", 9 | "isDesktopOnly": false 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "inlineSourceMap": true, 5 | "inlineSources": true, 6 | "module": "ESNext", 7 | "target": "ES6", 8 | "allowJs": true, 9 | "noImplicitAny": true, 10 | "moduleResolution": "node", 11 | "importHelpers": true, 12 | "isolatedModules": true, 13 | "strictNullChecks": true, 14 | "lib": [ 15 | "DOM", 16 | "ES5", 17 | "ES6", 18 | "ES7" 19 | ] 20 | }, 21 | "include": [ 22 | "**/*.ts" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /version-bump.mjs: -------------------------------------------------------------------------------- 1 | import { readFileSync, writeFileSync } from "fs"; 2 | 3 | const targetVersion = process.env.npm_package_version; 4 | 5 | // read minAppVersion from manifest.json and bump version to target version 6 | let manifest = JSON.parse(readFileSync("manifest.json", "utf8")); 7 | const { minAppVersion } = manifest; 8 | manifest.version = targetVersion; 9 | writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t")); 10 | 11 | // update versions.json with target version and minAppVersion from manifest.json 12 | let versions = JSON.parse(readFileSync("versions.json", "utf8")); 13 | versions[targetVersion] = minAppVersion; 14 | writeFileSync("versions.json", JSON.stringify(versions, null, "\t")); 15 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "env": { "node": true }, 5 | "plugins": [ 6 | "@typescript-eslint" 7 | ], 8 | "extends": [ 9 | "eslint:recommended", 10 | "plugin:@typescript-eslint/eslint-recommended", 11 | "plugin:@typescript-eslint/recommended" 12 | ], 13 | "parserOptions": { 14 | "sourceType": "module" 15 | }, 16 | "rules": { 17 | "no-unused-vars": "off", 18 | "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], 19 | "@typescript-eslint/ban-ts-comment": "off", 20 | "no-prototype-builtins": "off", 21 | "@typescript-eslint/no-empty-function": "off" 22 | } 23 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "list-style", 3 | "version": "0.1.0", 4 | "description": "Set ordered list style inline in Obsidian.md. Alphabetic lists, roman numeral lists, etc.", 5 | "main": "main.js", 6 | "scripts": { 7 | "dev": "node esbuild.config.mjs", 8 | "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", 9 | "version": "node version-bump.mjs && git add manifest.json versions.json" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "MIT", 14 | "devDependencies": { 15 | "@types/node": "^16.11.6", 16 | "@typescript-eslint/eslint-plugin": "5.29.0", 17 | "@typescript-eslint/parser": "5.29.0", 18 | "builtin-modules": "3.3.0", 19 | "esbuild": "0.14.47", 20 | "obsidian": "latest", 21 | "tslib": "2.4.0", 22 | "typescript": "4.7.4" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2022 Eric Rykwalder 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /esbuild.config.mjs: -------------------------------------------------------------------------------- 1 | import esbuild from "esbuild"; 2 | import process from "process"; 3 | import builtins from 'builtin-modules' 4 | 5 | const banner = 6 | `/* 7 | THIS IS A GENERATED/BUNDLED FILE BY ESBUILD 8 | if you want to view the source, please visit the github repository of this plugin 9 | */ 10 | `; 11 | 12 | const prod = (process.argv[2] === 'production'); 13 | 14 | esbuild.build({ 15 | banner: { 16 | js: banner, 17 | }, 18 | entryPoints: ['main.ts'], 19 | bundle: true, 20 | external: [ 21 | 'obsidian', 22 | 'electron', 23 | '@codemirror/autocomplete', 24 | '@codemirror/collab', 25 | '@codemirror/commands', 26 | '@codemirror/language', 27 | '@codemirror/lint', 28 | '@codemirror/search', 29 | '@codemirror/state', 30 | '@codemirror/view', 31 | '@lezer/common', 32 | '@lezer/highlight', 33 | '@lezer/lr', 34 | ...builtins], 35 | format: 'cjs', 36 | watch: !prod, 37 | target: 'es2018', 38 | logLevel: "info", 39 | sourcemap: prod ? false : 'inline', 40 | treeShaking: true, 41 | outfile: 'main.js', 42 | }).catch(() => process.exit(1)); 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ordered List Style 2 | 3 | This is a plugin for [Obsidian](https://obsidian.md). 4 | 5 | Set the style of ordered lists inline by adding details in the first list item. 6 | 7 | ```markdown 8 | 1. {A} a list with an upper-roman list ordering 9 | 2. This item will show as "B" 10 | 3. and this one as "C" 11 | ``` 12 | 13 | To set the style, the style name needs to be put in brackets before any other text. 14 | 15 | Any of the [list style types](https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type) can be used with their full name, like `upper-alpha`. Additionally there is shorthand available for some of the common types: 16 | 17 | - `{A}`: Upper alpha 18 | - `{a}`: Lower alpha 19 | - `{I}`: Upper roman 20 | - `{i}`: lower roman 21 | - `{01}`: decimal with leading zero 22 | - `{1}`: decimal (default, though this may not be the case in your theme) 23 | 24 | The list style cannot be changed mid-list, or by setting it in any element but the first. 25 | 26 | ## Gotchas 27 | 28 | On mobile, sub lists may take on their parent type by default. This can be corrected by manually setting it back to the default, or whichever style type you prefer. 29 | -------------------------------------------------------------------------------- /main.ts: -------------------------------------------------------------------------------- 1 | import { Plugin } from "obsidian"; 2 | 3 | const shorthand: { [key: string]: string } = { 4 | I: "upper-roman", 5 | i: "lower-roman", 6 | A: "upper-alpha", 7 | a: "lower-alpha", 8 | "01": "decimal-leading-zero", 9 | "1": "decimal", 10 | }; 11 | 12 | const STYLE_MATCHER = /^\s*\{([A-Za-z-0-9]+)\}\s*/; 13 | 14 | export default class ListStylePlugin extends Plugin { 15 | async onload() { 16 | this.registerMarkdownPostProcessor((el: HTMLElement) => { 17 | el.querySelectorAll("ol").forEach((list: HTMLElement) => { 18 | const firstText = getFirstTextNode( 19 | list.querySelector("li") as Node 20 | ); 21 | let match; 22 | if ( 23 | firstText && 24 | firstText.textContent && 25 | (match = firstText.textContent.match(STYLE_MATCHER)) 26 | ) { 27 | if (shorthand[match[1]]) { 28 | list.style.listStyleType = shorthand[match[1]]; 29 | } else { 30 | list.style.listStyleType = match[1]; 31 | } 32 | firstText.textContent = firstText.textContent.slice( 33 | match[0].length 34 | ); 35 | } 36 | }); 37 | }); 38 | } 39 | } 40 | 41 | function getFirstTextNode(node: Node | null): Text | null { 42 | if (node == null) return null; 43 | for (let i = 0; i < node.childNodes.length; i++) { 44 | if (node.childNodes[i].nodeType == Node.TEXT_NODE) { 45 | return node.childNodes[i] as Text; 46 | } else if (node.childNodes[i].hasChildNodes()) { 47 | const childText = getFirstTextNode(node.childNodes[i]); 48 | if (childText) { 49 | return childText; 50 | } 51 | } 52 | } 53 | return null; 54 | } 55 | --------------------------------------------------------------------------------