Skip to content

Commit

Permalink
Merge pull request #1 from phillipjohnston/pj/merge
Browse files Browse the repository at this point in the history
Improvements made in phillipjohnston/obsidian-pandoc
  • Loading branch information
AB1908 authored Mar 14, 2022
2 parents 8229273 + 54d4a3a commit c8cf21a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 47 deletions.
28 changes: 28 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import esbuild from "esbuild";
import process from "process";
import builtins from 'builtin-modules'

const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = (process.argv[2] === 'production');

esbuild.build({
banner: {
js: banner,
},
entryPoints: ['main.ts'],
bundle: true,
external: ['obsidian', 'electron', ...builtins],
format: 'cjs',
watch: !prod,
target: 'es2016',
logLevel: "info",
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: 'main.js',
}).catch(() => process.exit(1));
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "obsidian-pandoc-plugin",
"version": "0.1.0",
"version": "0.3.0",
"description": "This is a Pandoc export plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js --environment BUILD:production"
"dev": "node esbuild.config.mjs",
"build": "node esbuild.config.mjs production"
},
"keywords": [],
"author": "Oliver Balfour",
"author": "Obsidian Community",
"license": "MIT",
"devDependencies": {
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/node": "^14.14.2",
"obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master",
"rollup": "^2.32.1",
"tslib": "^2.0.3",
"typescript": "^4.0.3"
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"builtin-modules": "^3.2.0",
"esbuild": "0.13.12",
"obsidian": "^0.12.17",
"tslib": "2.3.1",
"typescript": "4.4.4"
},
"dependencies": {
"@types/temp": "^0.9.0",
Expand Down
25 changes: 21 additions & 4 deletions renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as path from 'path';
import * as fs from 'fs';
import * as YAML from 'yaml';

import { FileSystemAdapter, MarkdownRenderer, MarkdownView, Notice } from 'obsidian';
import { FileSystemAdapter, MarkdownRenderer, MarkdownView, Notice, resolveSubpath, parseLinktext } from 'obsidian';

import PandocPlugin from './main';
import { PandocPluginSettings } from './global';
Expand Down Expand Up @@ -173,16 +173,33 @@ async function postProcessRenderedHTML(plugin: PandocPlugin, inputFile: string,
for (let span of Array.from(wrapper.querySelectorAll('span.internal-embed'))) {
let src = span.getAttribute('src');
if (src) {
const subfolder = inputFile.substring(adapter.getBasePath().length); // TODO: this is messy
const file = plugin.app.metadataCache.getFirstLinkpathDest(src, subfolder);
const link_split = parseLinktext(src);
const subfolder = inputFile.substring(adapter.getBasePath().length); // TODO: this is messy
const file = plugin.app.metadataCache.getFirstLinkpathDest(link_split.path, subfolder);

try {
if (parentFiles.indexOf(file.path) !== -1) {
// We've got an infinite recursion on our hands
// We should replace the embed with a wikilink
// Then our link processing happens afterwards
span.outerHTML = `<a href="${file}">${span.innerHTML}</a>`;
} else {
const markdown = await adapter.read(file.path);
let markdown = await adapter.read(file.path);

if(link_split.subpath) {
const subpath_result = resolveSubpath(plugin.app.metadataCache.getFileCache(file), link_split.subpath);

if(subpath_result.type === "heading") {
// This will grab everything from the end of the selected heading (excluding the heading title!) to the start of the next heading)
let end_pos = subpath_result.next ? subpath_result.next.position.start.offset : markdown.length
markdown = markdown.substring(subpath_result.current.position.end.offset, end_pos);
} else {
// Grab the whole block without excluding titles
markdown = markdown.substring(subpath_result.block.position.start.offset, subpath_result.block.position.end.offset);
}

}

const newParentFiles = [...parentFiles];
newParentFiles.push(inputFile);
// TODO: because of this cast, embedded notes won't be able to handle complex plugins (eg DataView)
Expand Down
30 changes: 0 additions & 30 deletions rollup.config.js

This file was deleted.

3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"0.2.2": "0.12.5",
"0.2.3": "0.12.5",
"0.2.4": "0.12.5",
"0.2.5": "0.12.5"
"0.2.5": "0.12.5",
"0.3.0": "0.12.5",
}

0 comments on commit c8cf21a

Please sign in to comment.