Skip to content

Commit

Permalink
feat: update to README
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltomasz committed Jan 2, 2025
1 parent 61c71c2 commit 8f81e89
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 82 deletions.
133 changes: 69 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,108 @@
# qmd as md Obsidian plugin
# QMD as Markdown Obsidian Plugin

A plugin for [Obsidian](https://obsidian.md) which allows editing of qmd files as if they were markdown.
A plugin for [Obsidian](https://obsidian.md) that allows seamless editing of QMD files as if they were Markdown.

QMD files contain a combination of markdown and executable code cell, and are format supported by [Quarto](https://quarto.org/) open source publishing systems, they are supported in Rstudio and VSCode editors.
QMD files combine Markdown with executable code cells and are supported by [Quarto](https://quarto.org/), an open-source publishing system. These files are compatible with editors like RStudio and VSCode.

To be able to use linking with the quatro files you need to check the toggle "detect all files extension" in `Files & Links` section in Obsidian.
This plugin began as a small tweak to a now-defunct plugin created by deathau: [deathau/txt-as-md-obsidian](https://github.com/deathau/txt-as-md-obsidian). It has since evolved with additional integrations.

To hide additional files you might use this CSS chunk (save it as a file to your snippets folder and enable it in Obsidian in the Appeareance menu), you might add aditional filetypes.
---

## Version History

### 0.0.3
- Added an option to run Quarto preview for the current `qmd` file.

### 0.0.2
- Repurposed the plugin to enable viewing and editing of QMD files.
- Made the plugin available via BRAT and Obsidian.

### 0.0.1
- Initial release by death_md, supporting `.txt` files.

---

## To-Do List

- [ ] Recognize `{language}` for code block syntax highlighting.
- [ ] Add CSS support for callout blocks.
- [ ] Enable the creation of new QMD files.
- [ ] Add a render command.

---

## Enhancing Quarto File Integration in Obsidian

To enable linking with Quarto files, ensure the **"Detect all file extensions"** toggle is activated in the `Files & Links` section of Obsidian settings.

If you'd like to hide additional file types, use the following CSS snippet. Save it in your snippets folder and enable it via the Appearance menu in Obsidian. You can add more file extensions as needed.

```css
div[data-path$='.Rproj']{
div[data-path$='.Rproj'] {
display: none;
}

div[data-path$='.cls']{
div[data-path$='.cls'] {
display: none;
}

div[data-path$='.yml']{
div[data-path$='.yml'] {
display: none;
}

div[data-path$='.json']{
div[data-path$='.json'] {
display: none;
}
```
---

Plugin is a small tweak of a plugin made by deathau: [deathau/txt-as-md-obsidian: Edit txt files in Obsidian.md as if they were markdown](https://github.com/deathau/txt-as-md-obsidian).
## Compatibility

### Plugins for better editing experience
This plugin requires Obsidian **v0.10.12** or later to work properly, as the necessary APIs were introduced in this version.

- Use [obsidian-shellcomands](obsidian://show-plugin?id=obsidian-shellcommands) with `quarto render {{file_path:absolute}} --to pdf` to render the file inside Obsidian
- Use [HTML Reader](obsidian://show-plugin?id=obsidian-html-plugin) to render HTML output inside Obsidian, Obsidian natively supports pdfs.


### To-do

- [ ] Creation of new qmd files
- [ ] Currly braces `{language}` treated as language for codeblock
- [ ] CSS for callout blocks
- [ ] Better integration with Obsidian

### Compatibility

The required APIs were only added in Obsidian **0.10.12**, and as such, that is the minimum version of Obsidian required to use this plugin.
---

## Installation

### From within Obsidian
### From Within Obsidian

Plugin is accesible in the Obsidian n the community list. If you want to test beta releases, you can use [the BRAT plugin](https://github.com/TfTHacker/obsidian42-brat).
The plugin is available in Obsidian's community plugin list.
For beta releases, you can use the [BRAT plugin](https://github.com/TfTHacker/obsidian42-brat).

### From GitHub
- Download the Latest Release from the Releases section of the GitHub Repository
- Extract the plugin folder from the zip to your vault's plugins folder: `<vault>/.obsidian/plugins/`
Note: On some machines the `.obsidian` folder may be hidden. On MacOS you should be able to press `Command+Shift+Dot` to show the folder in Finder.
- Reload Obsidian
- If prompted about Safe Mode, you can disable safe mode and enable the plugin.
Otherwise head to Settings, third-party plugins, make sure safe mode is off and
enable the plugin from there.

## Security
> Third-party plugins can access files on your computer, connect to the internet, and even install additional programs.
1. Download the latest release from the Releases section of the GitHub repository.
2. Extract the plugin folder from the zip file to your vault's plugins directory: `<vault>/.obsidian/plugins/`
- Note: On some systems, the `.obsidian` folder might be hidden. On macOS, press `Command + Shift + Dot` to reveal hidden folders in Finder.
3. Reload Obsidian.
4. If prompted about Safe Mode, disable it and enable the plugin.
Alternatively, go to **Settings → Third-party plugins**, disable Safe Mode, and enable the plugin manually.

The source code of this plugin is available on GitHub for you to audit yourself, but installing plugins into Obsidian is currently a matter of trust.
---

I can assure you here that I do nothing to collect your data, send information to the internet or otherwise do anything nefarious with your system. However, be aware that I *could*, and you only have my word that I don't.
## Security

## Development
> **Important:** Third-party plugins can access files on your computer, connect to the internet, and install additional programs.
This project uses Typescript to provide type checking and documentation.
The repo depends on the latest [plugin API](https://github.com/obsidianmd/obsidian-api) in Typescript Definition format, which contains TSDoc comments describing what it does.
The source code for this plugin is open and available on GitHub for audit. While I assure you that the plugin does not collect data or perform any malicious actions, installing plugins in Obsidian always involves a level of trust.

**Note:** The Obsidian API is still in early alpha and is subject to change at any time!
---

## Development

If you want to contribute to development and/or just customize it with your own
tweaks, you can do the following:
- Clone this repo.
- `npm i` or `yarn` to install dependencies
- `npm run build` to compile.
- Copy `manifest.json`, `main.js` and `styles.css` to a subfolder of your plugins
folder (e.g, `<vault>/.obsidian/plugins/<plugin-name>/`)
- Reload obsidian to see changes
This project is built using TypeScript for type checking and documentation.
It relies on the latest [Obsidian plugin API](https://github.com/obsidianmd/obsidian-api) in TypeScript Definition format, which includes TSDoc comments for documentation.

Alternately, you can clone the repo directly into your plugins folder and once
dependencies are installed use `npm run dev` to start compilation in watch mode.
You may have to reload obsidian (`ctrl+R`) to see changes.
**Note:** The Obsidian API is in early alpha and may change at any time.

## Pricing
To contribute or customize the plugin:

Plugin is completely free, but you might contribute to the author of the orginal plugin (deathau) via the following:
1. Clone this repository.
2. Run `npm i` or `yarn` to install dependencies.
3. Use `npm run build` to compile the plugin.
4. Copy `manifest.json`, `main.js`, and `styles.css` to a subfolder in your plugins directory: `<vault>/.obsidian/plugins/<plugin-name>/`
5. Reload Obsidian to apply changes.

[![GitHub Sponsors](https://img.shields.io/github/sponsors/deathau?style=social)](https://github.com/sponsors/deathau)
[![Paypal](https://img.shields.io/badge/paypal-deathau-yellow?style=social&logo=paypal)](https://paypal.me/deathau)
Alternatively, clone the repository directly into your plugins folder. After installing dependencies, run `npm run dev` to enable watch mode for live compilation.
Reload Obsidian (`Ctrl + R`) to view updates.

# Version History
## 0.0.1
Initial release by death_md supporting txt!
## 0.0.2
Repurposing this plugin to viev and edit qmd files, plugin available via BRAT.
# 0.0.3
Optopn to run preview
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ zip:
zip qmd-as-md.zip main.js manifest.json

clean:
rm -rf node_modules dist build .cache *.log *.tmp package-lock.json main.js
rm -rf node_modules dist build .cache *.log *.tmp package-lock.json

build:
npm install && npm run build && make zip && make clean
Binary file removed qmd-as-md-working.zip
Binary file not shown.
Binary file modified qmd-as-md.zip
Binary file not shown.
44 changes: 27 additions & 17 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import * as path from 'path';
interface QmdPluginSettings {
quartoPath: string;
enableQmdLinking: boolean;
quartoTypst: string; // Add Quarto Typst variable
quartoTypst: string;
emitCompilationLogs: boolean; // New setting
}

const DEFAULT_SETTINGS: QmdPluginSettings = {
quartoPath: 'quarto',
enableQmdLinking: true,
quartoTypst: '', // Default is empty
quartoTypst: '',
emitCompilationLogs: true, // Default is to emit logs
};

export default class QmdAsMdPlugin extends Plugin {
Expand Down Expand Up @@ -124,14 +126,12 @@ export default class QmdAsMdPlugin extends Plugin {
console.log(`Working directory: ${workingDir}`);

const envVars: NodeJS.ProcessEnv = {
...process.env, // inherit the existing environment
...process.env,
};

if (this.settings.quartoTypst.trim()) {
envVars.QUARTO_TYPST = this.settings.quartoTypst.trim();
console.log(`QUARTO_TYPST set to: ${envVars.QUARTO_TYPST}`);
} else {
console.log('QUARTO_TYPST not set (empty).');
}

const quartoProcess = spawn(this.settings.quartoPath, ['preview', filePath], {
Expand All @@ -143,7 +143,9 @@ export default class QmdAsMdPlugin extends Plugin {

quartoProcess.stdout?.on('data', (data: Buffer) => {
const output = data.toString();
console.log(`Quarto Preview Output: ${output}`);
if (this.settings.emitCompilationLogs) {
console.log(`Quarto Preview Output: ${output}`);
}

if (output.includes('Browse at')) {
const match = output.match(/Browse at\s+(http:\/\/[^\s]+)/);
Expand All @@ -165,8 +167,9 @@ export default class QmdAsMdPlugin extends Plugin {
});

quartoProcess.stderr?.on('data', (data: Buffer) => {
console.error(`Quarto Preview Error: ${data}`);
new Notice(`Quarto Preview Error: ${data}`);
if (this.settings.emitCompilationLogs) {
console.error(`Quarto Preview Error: ${data}`);
}
});

quartoProcess.on('close', (code: number | null) => {
Expand Down Expand Up @@ -239,26 +242,20 @@ class QmdSettingTab extends PluginSettingTab {
);

new Setting(containerEl)
.setName('Enable Linking to Quarto Files')
.setName('Enable Editing Quarto Files')
.setDesc(
'Allow linking to `.qmd` files without enabling "Detect All File Extensions"'
'By default it allows editing `.qmd` files, disable it case of conflict with `Custom File Extensionbs and Types` plugin'
)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.enableQmdLinking)
.onChange(async (value) => {
console.log(`Enable QMD Linking setting changed to: ${value}`);
console.log(`Enable QMD Editing setting changed to: ${value}`);
this.plugin.settings.enableQmdLinking = value;

if (value) {
this.plugin.registerQmdExtension();
} else {
console.log(
'.qmd linking disabled. Restart Obsidian if required.'
);
}

await this.plugin.saveSettings();
})
);

Expand All @@ -276,6 +273,19 @@ class QmdSettingTab extends PluginSettingTab {
})
);

new Setting(containerEl)
.setName('Emit Compilation Logs')
.setDesc('Toggle whether to emit detailed compilation logs in the console')
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.emitCompilationLogs)
.onChange(async (value) => {
console.log(`Emit Compilation Logs set to: ${value}`);
this.plugin.settings.emitCompilationLogs = value;
await this.plugin.saveSettings();
})
);

console.log('Settings tab rendered successfully');
}
}

0 comments on commit 8f81e89

Please sign in to comment.