PHPackages                             elazar/league-commonmark-obsidian - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. elazar/league-commonmark-obsidian

ActiveCommonmark-extension[Parsing &amp; Serialization](/categories/parsing)

elazar/league-commonmark-obsidian
=================================

Parser for use with league/commonmark to parse Obsidian Markdown

2.1.0(3y ago)4791MITPHP

Since Nov 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/elazar/league-commonmark-obsidian)[ Packagist](https://packagist.org/packages/elazar/league-commonmark-obsidian)[ RSS](/packages/elazar-league-commonmark-obsidian/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

League Commonmark Obsidian Extension
====================================

[](#league-commonmark-obsidian-extension)

[![PHP Version Support](https://camo.githubusercontent.com/931f01de40e1c697c856a3844be43e6789e42d7a8d594d9fec9d82360a69fd93/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d706870266d6573736167653d2533453d253230382e302e3226636f6c6f723d626c756576696f6c6574)](https://packagist.org/packages/elazar/flystream)[![Packagist Version](https://camo.githubusercontent.com/7c6fac8a19eca29361ffe795ff1f01dc990aaba7bbe2e5d254133037e3b9b341/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d7061636b6167697374266d6573736167653d322e312e3026636f6c6f723d626c756576696f6c6574)](https://packagist.org/packages/elazar/flystream)[![Software License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Buy Me a Cofee](https://camo.githubusercontent.com/a7f157b5d5704aa73ce2a28eda195d4f78527897562070e2bdf201bd743bc3d4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275792532306d6525323061253230636f666665652d646f6e6174652d627269676874677265656e2e737667)](https://ko-fi.com/elazar)

An extension for [`league/commonmark`](https://commonmark.thephpleague.com/) to render elements specific to [Obsidian](https://obsidian.md).

Released under the [MIT License](LICENSE).

Requirements
------------

[](#requirements)

- PHP 8.0.2+

Installation
------------

[](#installation)

Use [Composer](https://getcomposer.org/).

If you want to install this library [globally](https://getcomposer.org/doc/03-cli.md#global) to use the conversion script it provides:

```
composer global require elazar/league-commonmark-obsidian
```

If you want to install this library locally for use in your own codebase:

```
composer require elazar/league-commonmark-obsidian
```

Usage
-----

[](#usage)

There are three ways to use this library.

### Conversion Script

[](#conversion-script)

The conversion script requires only a single command to run, but offers a very minimal conversion with no options for customization. It is mainly intended to provide a minimal example of using the converter (see the next section), but can be invoked like so:

```
composer global exec obsidian-to-html /path/to/vault /path/to/vault/Attachments /path/to/build
```

- `/path/to/vault` is the path to the root directory of the Obsidian vault to convert to HTML
- `/path/to/vault/Attachments` is the path to the subdirectory of the Obsidian vault that contains attachments
- `/path/to/build` is the path to the directory to receive the converted HTML

### Extension

[](#extension)

If you want to use the extension in your own code, you can do so as follows.

```
$extension = new Elazar\LeagueCommonMarkObsidian\LeagueCommonMarkObsidianExtension(
    vaultPath: '/path/to/Vault',
    attachmentsPath: '/path/to/Vault/Attachments',
);

$environment = new League\CommonMark\Environment\Environment;
$environment->addExtension(new League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension);
$environment->addExtension($extension);

$converter = new League\CommonMark\MarkdownConverter($environment);

// Set the absolute path of the file being converted so that
// links can be resolved relative to that file
$extension->setFromPath('/path/to/Vault/Folder/File.md');

echo $converter->convert('[[Internal Link]]');
// Assuming that "Internal Link.md" is contained in the root
// directory of the vault, the above line outputs:
// Internal Link

echo $converter->convert('![[Attachment.pdf]]');
// Assuming that "Attachment.pdf" is contained in the "Attachments"
// subdirectory within the vault directory, the above line
// outputs:
```

### Converter

[](#converter)

The converter is a single class that can be used in your own conversion script or other code. It requires writing a bit of PHP code to use it, but offers more options for customization than the stock conversion script, such as including more [extensions](https://commonmark.thephpleague.com/2.3/customization/extensions/) in the [environment](https://commonmark.thephpleague.com/2.3/customization/environment/) configuration or formatting the converted HTML.

Below is an example that adds the [Strikethrough extension](https://commonmark.thephpleague.com/2.3/extensions/strikethrough/) and a custom formatter that wraps the converted HTML in additional markup.

```
$vaultPath = '/path/to/vault';
$attachmentsPath = $vaultPath. '/Attachments';
$buildPath = __DIR__ . '/build';

$formatter = new class implements Elazar\LeagueCommonMarkObsidian\Formatter\FormatterInterface {
    public function format(string $html, string $markdownFilePath): string {
        $title = str_replace('.md', '', basename($markdownFilePath));
        return addExtension($extension);

$converter = new Elazar\LeagueCommonMarkObsidian\Converter;
$converter->convert($vaultPath, $attachmentsPath, $buildPath, $environment, $formatter);
```

Internals
---------

[](#internals)

In some instances, it can be helpful to be familiar with the internals of this library.

Here are some example use cases:

1. If you want to contribute to this library, it's helpful to know what parts of the codebase you may need to modify to implement a given feature or fix a given bug.
2. If you find a bug in this library and want to work around it, it may be possible to do so by overriding specific components of the library.
3. If Obsidian adds support for a new attachment file type and you want to add support for it to this library before it's added to the library's core, you may be able to do so by adding to the embed renderers it uses.

### Extension

[](#extension-1)

The normal use case for [`LeagueCommonMarkObsidianExtension`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/LeagueCommonMarkObsidianExtension.php) is for it to receive a vault path and attachments path. In lieu of these, it can receive other dependencies detailed in subsequent sections of this document.

The main function of the extension is to add two inline parsers to the environment: [`InternalLinkParser`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/Parser/InternalLinkParser.php) for [internal links](https://help.obsidian.md/How+to/Internal+link) and [`EmbedParser`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/Parser/EmbedParser.php) for [embeds](https://help.obsidian.md/How+to/Format+your+notes).

The internal link parser renders a natively supported link element. The embed parser uses its own renderers to render custom inline HTML elements, as at least some of these are not natively supported by CommonMark.

### Embed Renderer

[](#embed-renderer)

The [`EmbedRendererInterface`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/Renderer/EmbedRendererInterface.php) `$embedRenderer` parameter of [`LeagueCommonMarkObsidianExtension`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/LeagueCommonMarkObsidianExtension.php) is used to render [embeds](https://help.obsidian.md/How+to/Format+your+notes).

The default used for `$embedRenderer` is an instance of [`EmbedRenderer`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/Renderer/EmbedRenderer.php), which extends [`CompositeEmbedRenderer`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/Renderer/CompositeEmbedRenderer.php) and composes all other renderers included in this library. It attempts to use each of these renderers in turn to render a given embed.

### Attachment Link Resolver

[](#attachment-link-resolver)

The [`LinkResolverInterface`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/Resolver/LinkResolverInterface.php) `$attachmentLinkResolver` parameter of [`LeagueCommonMarkObsidianExtension`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/LeagueCommonMarkObsidianExtension.php) is used to resolve links for [embedded](https://help.obsidian.md/How+to/Embed+files#Embed+attachments) [attachments](https://help.obsidian.md/How+to/Manage+attachments).

The default used for `$attachmentLinkResolver` is an instance of [`AttachmentLinkResolver`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/Resolver/AttachmentLinkResolver.php), which uses the vault and attachment paths to resolve attachment links and embeds relative to the Markdown file being rendered as HTML.

### Internal Link Resolver

[](#internal-link-resolver)

The [`LinkResolverInterface`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/Resolver/LinkResolverInterface.php) `$internalLinkResolver` parameter of [`LeagueCommonMarkObsidianExtension`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/LeagueCommonMarkObsidianExtension.php) is used to resolve [internal links](https://help.obsidian.md/How+to/Internal+link).

The default used for `$internalLinkResolver` is an instance of [`InternalLinkResolver`](https://github.com/elazar/league-commonmark-obsidian/blob/master/src/Resolver/InternalLinkResolver.php), which uses the vault path to resolve internal links relative to the Markdown file being rendered as HTML.

Contributing
------------

[](#contributing)

Regardless of how you want to contribute, please start by [filing an issue](https://github.com/elazar/league-commonmark-obsidian).

### Issues

[](#issues)

Please prefix issue titles with one of the following:

- **Bug Report** (if you find behavior you believe to be a bug)
- **Feature Request** (if you would like to suggest an addition or change to the library)
- **Help Request** (for everything you aren't sure about)

Doing this allows for discussion with maintainers to troubleshoot problems, confirm bugs, or determine how best to make suggested features work.

In cases where you wish to contribute code, this discussion may help to clarify your implementation approach and reduce potential rework required on your part to get your contribution merged.

Help requests are closed once they are resolved or if they are inactive for 30 days. Other issues are left open until either a related PR is merged or a formal decision is made by the maintainers that no further action will be taken.

### Pull Requests

[](#pull-requests)

Once consensus is reached on a bug or feature implementation approach, file a PR using a branch with a name prefixed with either `bug/` or `feature/` for a bug report or feature request respectively.

Please be sure to reference the original issue you filed in your PR description to provide context for the changes.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Total

3

Last Release

1164d ago

Major Versions

1.0.0 → 2.0.02023-01-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/80dec604abed1b21daafc54c430468444a2ad163ad5f8229348b8d241b797778?d=identicon)[elazar](/maintainers/elazar)

---

Top Contributors

[![elazar](https://avatars.githubusercontent.com/u/15487?v=4)](https://github.com/elazar "elazar (9 commits)")[![tyson-nw](https://avatars.githubusercontent.com/u/1661582?v=4)](https://github.com/tyson-nw "tyson-nw (1 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/elazar-league-commonmark-obsidian/health.svg)

```
[![Health](https://phpackages.com/badges/elazar-league-commonmark-obsidian/health.svg)](https://phpackages.com/packages/elazar-league-commonmark-obsidian)
```

###  Alternatives

[spatie/laravel-markdown

A highly configurable markdown renderer and Blade component for Laravel

4053.4M35](/packages/spatie-laravel-markdown)[mnapoli/front-yaml

2895.6M45](/packages/mnapoli-front-yaml)[daux/daux.io

Documentation generator that uses a simple folder structure and Markdown files to create custom documentation on the fly

825191.0k1](/packages/daux-dauxio)[spatie/sheets

Store &amp; retrieve your static content in plain text files

30187.7k4](/packages/spatie-sheets)[prezet/prezet

Prezet: Markdown Blogging for Laravel

2969.8k2](/packages/prezet-prezet)[sinnbeck/markdom

Converts markdown to html with classes

69122.6k2](/packages/sinnbeck-markdom)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
