Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from OliverBalfour/obsidian-pandoc #8

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .autorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": [
"obsidian"
],
"author": "Oliver Balfour <[email protected]>"
}
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Based on https://github.com/hipstersmoothie/obsidian-plugin-prettier/blob/main/.github/workflows/main.yml
name: Release
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Prepare repository
run: git fetch --unshallow --tags

- name: Install modules
run: yarn

- name: Run build
run: yarn run build

- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: |
npm run release
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# npm
node_modules
package-lock.json
yarn.lock

data.json

Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 0.4.1 (Sun Sep 25 2022)

#### 🐛 Bug Fix

- Fix issue #67 [#130](https://github.com/OliverBalfour/obsidian-pandoc/pull/130) ([@frogkind](https://github.com/frogkind))

#### Authors: 1

- Chuang Zheng ([@frogkind](https://github.com/frogkind))

---

# 0.3.0 (Sun Sep 25 2022)

#### 🚀 Enhancement

- Some patches [#140](https://github.com/OliverBalfour/obsidian-pandoc/pull/140) ([@phillipjohnston](https://github.com/phillipjohnston) [@janLo](https://github.com/janLo) [@OliverBalfour](https://github.com/OliverBalfour))

#### Authors: 3

- [@OliverBalfour](https://github.com/OliverBalfour)
- Jan Losinski ([@janLo](https://github.com/janLo))
- Phillip Johnston ([@phillipjohnston](https://github.com/phillipjohnston))
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Note: this plugin is in beta, and there are often minor formatting issues. Make

## [Installation](https://github.com/OliverBalfour/obsidian-pandoc/wiki/Installation)

(Installation instructions are on the wiki, use the above link)
Installation instructions are on the wiki, use the above link

Developer setup instructions are in [development.md](./development.md)

## Basic usage
* Press Ctrl+P/Cmd+P to show the command palette
Expand Down
45 changes: 18 additions & 27 deletions development.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@

### Releasing new releases

- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release.
- Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible.
- Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases
- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments.
- Publish the release.

### Adding your plugin to the community plugin list

- Publish an initial version.
- Make sure you have a `README.md` file in the root of your repo.
- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.

### How to use

- Clone this repo.
- `npm i` or `yarn` to install dependencies
- `npm run dev` to start compilation in watch mode.

### Manually installing the plugin

- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.

### API Documentation

See https://github.com/obsidianmd/obsidian-api
### Setup

* `cd vault/.obsidian/plugins`
* If you already have the plugin, copy the `obsidian-pandoc/data.json` file somewhere safe and delete the plugin
* `git clone https://github.com/OliverBalfour/obsidian-pandoc` (or clone it elsewhere and make a symlink here)
* Copy the data file back in
* `cd obsidian-pandoc`
* `npm install`

### Development

Every time you want to edit the plugin:
* `npm run dev` (keep this running until you're done)
* Commit+push your changes like normal (don't worry about version numbers)
* Make a PR and add the patch/minor/major label depending on how big the change is
* When it's reviewed and merged, a GitHub Actions workflow will
1. Automatically increment all the version numbers in a new commit
2. Build and publish a release
6 changes: 4 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export default class PandocPlugin extends Plugin {
const result = await pandoc(
{
file: 'STDIN', contents: html, format: 'html', metadataFile,
pandoc: this.settings.pandoc, pdflatex: this.settings.pdflatex
pandoc: this.settings.pandoc, pdflatex: this.settings.pdflatex,
directory: path.dirname(inputFile),
},
{ file: outputFile, format },
this.settings.extraArguments.split('\n')
Expand All @@ -133,7 +134,8 @@ export default class PandocPlugin extends Plugin {
const result = await pandoc(
{
file: inputFile, format: 'markdown',
pandoc: this.settings.pandoc, pdflatex: this.settings.pdflatex
pandoc: this.settings.pandoc, pdflatex: this.settings.pdflatex,
directory: path.dirname(inputFile),
},
{ file: outputFile, format },
this.settings.extraArguments.split('\n')
Expand Down
16 changes: 8 additions & 8 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "obsidian-pandoc",
"name": "Pandoc Plugin",
"version": "0.3.0",
"minAppVersion": "0.12.5",
"description": "This is a Pandoc export plugin for Obsidian. It provides commands to export to formats like DOCX, ePub and PDF.",
"author": "Oliver Balfour",
"authorUrl": "https://github.com/OliverBalfour/obsidian-pandoc",
"isDesktopOnly": true
"id": "obsidian-pandoc",
"name": "Pandoc Plugin",
"version": "0.4.1",
"minAppVersion": "0.12.5",
"description": "This is a Pandoc export plugin for Obsidian. It provides commands to export to formats like DOCX, ePub and PDF.",
"author": "Oliver Balfour",
"authorUrl": "https://github.com/OliverBalfour/obsidian-pandoc",
"isDesktopOnly": true
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{
"name": "obsidian-pandoc-plugin",
"version": "0.3.0",
"description": "This is a Pandoc export plugin for Obsidian (https://obsidian.md)",
"description": "Document exporting plugin for Obsidian using Pandoc",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "node esbuild.config.mjs production"
"build": "node esbuild.config.mjs production",
"release": "auto shipit"
},
"keywords": [],
"author": "Obsidian Community",
"author": "Oliver Balfour <[email protected]>",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"auto": "^10.37.6",
"auto-plugin-obsidian": "^0.1.4",
"builtin-modules": "^3.2.0",
"esbuild": "0.13.12",
"obsidian": "^0.12.17",
Expand All @@ -23,6 +26,7 @@
"dependencies": {
"@types/temp": "^0.9.0",
"lookpath": "^1.2.0",
"js-base64": "^3.7.2",
"temp": "^0.9.4",
"yaml": "^2.0.0-4"
}
Expand Down
11 changes: 5 additions & 6 deletions pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface PandocInput {
metadataFile?: string, // path to YAML file
pandoc?: string, // optional path to Pandoc if it's not in the current PATH variable
pdflatex?: string, // ditto for pdflatex
directory: AbsoluteFilePath, // The working directory (where the original source file is)
}

export interface PandocOutput {
Expand Down Expand Up @@ -146,19 +147,17 @@ export const pandoc = async (input: PandocInput, output: PandocOutput, extraPara
// Spawn a Pandoc child process
// Assumes Pandoc is installed and that the arguments are valid
// The arguments aren't sanitised, so be careful!
const env = Object.assign(process.env);

if (input.pdflatex) {
// Workaround for Windows having different PATH delimiters
// to *every other operating system in existence*
// *sigh*
if (process.platform === 'win32')
env.PATH += ";"
process.env.PATH += ";"
else
env.PATH += ":";
env.PATH += path.dirname(input.pdflatex);
process.env.PATH += ":";
process.env.PATH += path.dirname(input.pdflatex);
}
pandoc = spawn(input.pandoc || 'pandoc', args, { env: process.env });
pandoc = spawn(input.pandoc || 'pandoc', args, { env: process.env, cwd: input.directory });

if (stdin) {
// TODO: strip some unicode characters but not others
Expand Down
3 changes: 2 additions & 1 deletion renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import * as path from 'path';
import * as fs from 'fs';
import * as YAML from 'yaml';
import { Base64 } from 'js-base64';

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

Expand Down Expand Up @@ -284,7 +285,7 @@ function convertSVGToPNG(svg: SVGSVGElement, scale: number = 1): Promise<HTMLIma
canvas.height = Math.ceil(svg.height.baseVal.value * scale);
const ctx = canvas.getContext('2d');
var svgImg = new Image;
svgImg.src = "data:image/svg+xml;base64," + btoa(svg.outerHTML);
svgImg.src = "data:image/svg+xml;base64," + Base64.encode(svg.outerHTML);
return new Promise((resolve, reject) => {
svgImg.onload = () => {
ctx.drawImage(svgImg, 0, 0, canvas.width, canvas.height);
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"0.2.3": "0.12.5",
"0.2.4": "0.12.5",
"0.2.5": "0.12.5",
"0.3.0": "0.12.5",
"0.3.0": "0.12.5"
}