Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingislost committed Sep 4, 2021
0 parents commit 64b43cb
Show file tree
Hide file tree
Showing 11 changed files with 870 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Intellij
*.iml
.idea

# npm
node_modules
package-lock.json

# build
main.js
*.js.map

# obsidian
data.json
674 changes: 674 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Obsidian Print Preview

This plugin helps theme designers debug export to pdf issues by allowing them to inspect the print results

### Features

<img src="imgs/obsidian-print-preview.gif" alt="plugin demo" style="zoom: 67%;" />

- Regex functionality added to the default Obsidian search
- Regex also works with Search & Replace
- Capture groups are now supported for replacement
- Use dollar sign references to refer to capture groups: $1 $2 etc
- Support for case-insensitive mode using /foo/i

### Instructions

- Export to PDF as you normally would
- After export, the rendered print window will show up overlaid on top of your workspace
- You can now use the Dev Tools inspector to check the styling of the printed content
- To dismiss the print window, left click anywhere in the workspace

### FAQ

- My PDF doesn't look like the print preview
- Make sure to set "Emulate CSS media type" to "print" in chrome (see the demo video for details)
- I dismissed the print preview and now my Obisidian screen is blank
- Make sure to turn "Emulate CSS media type" back to "no emulation" as the default Obsidian theme hides all UI elements in print media mode.

### Not currently supported

- Viewing the preview prior to PDF creation
- The preview will only be visible after export has completed.
- Downscale support
- Currently the preview will show at 100% despite the % specified in the downscale setting

### Manually installing the plugin

- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/obsidian-print-preview/`.
Binary file added imgs/obsidian-print-preview.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "obsidian-print-preview",
"name": "Print Preview",
"version": "0.0.1",
"minAppVersion": "0.9.12",
"description": "This plugin helps theme designers debug export to pdf issues by allowing them to inspect the print results",
"author": "NothingIsLost",
"authorUrl": "https://github.com/nothingislost",
"isDesktopOnly": true
}
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "obsidian-print-preview",
"version": "0.0.1",
"description": "This plugin helps theme designers debug export to pdf issues by allowing them to inspect the print results",
"main": "main.js",
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js --environment BUILD:production"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.1",
"@types/node": "^14.14.37",
"obsidian": "^0.12.0",
"rollup": "^2.32.1",
"rollup-plugin-copy": "^3.3.0",
"tslib": "^2.2.0",
"typescript": "^4.2.4"
}
}
37 changes: 37 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import typescript from '@rollup/plugin-typescript';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';

const isProd = (process.env.BUILD === 'production');

const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP
if you want to view the source visit the plugins github repository
*/
`;

export default {
input: './src/main.ts',
output: {
dir: './dist/',
sourcemap: 'inline',
sourcemapExcludeSources: isProd,
format: 'cjs',
exports: 'default',
banner,
},
external: ['obsidian'],
plugins: [
typescript(),
nodeResolve({browser: true}),
commonjs(),
copy({
targets: [
{ src: 'manifest.json', dest: './dist/' },
{ src: 'styles.css', dest: './dist/' }
], flatten: true
})
]
};
25 changes: 25 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Plugin } from "obsidian";

export default class PrintPreview extends Plugin {
private observer: MutationObserver;

onload() {
const bodyEl = document.querySelector("body")
this.observer = new MutationObserver((mutations, observer) => {
mutations.forEach((mutation) => {
mutation.removedNodes.forEach((nodeEl) => {
if ((nodeEl as HTMLElement).className == 'print') {
(nodeEl as HTMLElement).addClass('print-preview');
// (nodeEl as HTMLElement).querySelector(".markdown-preview-view").addClass('markdown-preview-section')
bodyEl.appendChild(nodeEl);
}
});
});
});
this.observer.observe(bodyEl, { childList: true, subtree: false })
}

onunload() {
this.observer.disconnect()
}
}
23 changes: 23 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.print-preview .markdown-preview-view {
margin: auto;
width: 50rem; /* this appears to be the static width of the PDF output */
z-index: 1;
background-color: white;
}

.print-preview {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 1;
overflow: scroll;
background-color: var(--background-primary);
}

@media print {
* {
-webkit-print-color-adjust: exact;
}
}
22 changes: 22 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"baseUrl": ".",
"inlineSourceMap": true,
"inlineSources": true,
"module": "ESNext",
"target": "es6",
"allowJs": true,
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"lib": [
"dom",
"es5",
"scripthost",
"es2015"
]
},
"include": [
"**/*.ts"
]
}
3 changes: 3 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"0.0.1": "0.9.12"
}

0 comments on commit 64b43cb

Please sign in to comment.