diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 1a03a7b..bef75ed 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -1,31 +1,22 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -name: Upload Python Package +name: Semantic Release on: - release: - types: [created] + push: + branches: + - main jobs: - deploy: - + release: runs-on: ubuntu-latest + concurrency: release steps: - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* + fetch-depth: 0 + - name: Python Semantic Release + uses: relekang/python-semantic-release@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + repository_username: __token__ + repository_password: ${{ secrets.PYPI_TOKEN }} diff --git a/.gitignore b/.gitignore index d68469f..bc787c2 100644 --- a/.gitignore +++ b/.gitignore @@ -133,3 +133,4 @@ dmypy.json .pyre/ .vscode/launch.json +.idea/* diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..7bfddd9 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +.idea/* +.idea \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a4abefd --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,423 @@ +# CHANGELOG + + + +## v0.3.4 (2023-10-20) + +### Fix + +* fix(deprecation): remove warning_filter + +fix #1 ([`380116f`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/380116f20898b64bf75b00110e8d61d05aeabc34)) + + +## v0.3.3 (2022-12-08) + +### Fix + +* fix: update for mkdocs 1.4.0 ([`dc1741f`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/dc1741fb1601a181edfe072bb3feadbefe09558a)) + +### Unknown + +* attemp to fix broken build (not success) ([`8666a79`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/8666a795b5e23dbe69f3d06b4f1bfea30ee730da)) + +* remove idea ([`8f3a8d6`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/8f3a8d62ecafc3e03dc6ada4cfd53b7959edb6f8)) + +* remove idea ([`b9e3d13`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/b9e3d13783c923aa2be6cc5381c6ad3ba12f79a0)) + +* remove idea ([`4e45055`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/4e4505562bafe5ebf839818d73d8d2697b8fd558)) + + +## v0.3.2 (2022-10-01) + +### Fix + +* fix: relative file not found ([`1a03bfa`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/1a03bfa3db016eb18acc4c710a2bf0682ae1a01e)) + + +## v0.3.1 (2022-10-01) + +### Fix + +* fix: relative file not found ([`11ff9b2`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/11ff9b2468004876ca20cbec688843c0d0d8e1b5)) + + +## v0.3.0 (2022-07-13) + + +## v0.2.1 (2022-07-13) + +### Fix + +* fix: remove uncessary logging message ([`9c702a8`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/9c702a849ef577ee8dad766b04355ae95e41310c)) + +### Unknown + +* Update types.py ([`e2668e9`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/e2668e95bf564079d936cf81ebe67759e676900e)) + + +## v0.2.0 (2022-06-23) + +### Unknown + +* revert: revert update ([`a47512d`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/a47512db9e00d97d701a5bbfd86cf89b002a637a)) + + +## v0.1.19 (2022-06-23) + +### Fix + +* fix: image created with wikilinks that don't end with image format ([`edd395a`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/edd395afe84e2c56f275fe3543cc2f63ed3ea4f8)) + + +## v0.1.18 (2022-03-28) + +### Unknown + +* Merge branch 'main' of github.com:Mara-Li/mkdocs-ezlinked-plugin ([`504d117`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/504d117c3fa3b31e0e7d2dc011145025a7d22961)) + + +## v0.1.17 (2022-03-28) + +### Ci + +* ci: Update requirements & build ([`e5c9920`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/e5c992034849b63e67ac0c9f11db8a7627b2ba7c)) + +* ci: Add semantic workflow ([`44aeb20`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/44aeb2024f9ddaa46a0c463166a806b126b63817)) + +* ci: strict requirements ([`723e7d4`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/723e7d441ffb40ac9d5c58182ee8097231eb420c)) + +### Fix + +* fix: Update to mkdocs 1.3.0 ([`86d8313`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/86d83132d8c3967e2fa7f89df7647d5393695648)) + +* fix: Update to mkdocs 1.3.0 ([`6529730`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/652973032718f9f2f49c837461762d4c1a88fe8e)) + +### Unknown + +* Update python-publish.yml ([`00276da`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/00276da9ca1365f42a5f2fcaf0c9726a8d55972c)) + +* Merge branch 'main' of github.com:Mara-Li/mkdocs-ezlinked-plugin ([`6489c0c`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/6489c0cf6f82732f9b7072dbe71de5909832b495)) + +* Update requirements.txt ([`1f17f3b`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/1f17f3b70f5fa74437859c8ce748edb4171d759c)) + +* Merge branch 'main' of github.com:Mara-Li/mkdocs-ezlinks-plugin ([`e77b6e0`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/e77b6e02f92ebd16643360086e7890cfb08bc2b7)) + +* Update README.md ([`f9aa3c2`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/f9aa3c27cd123f736fa0bada94480444a9e7cc80)) + +* Update README.md ([`b5c33d5`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/b5c33d5ba852db4015f5386453b0e7ccee47faec)) + + +## v0.1.16 (2022-03-23) + + +## v0.1.15 (2022-03-23) + +### Ci + +* ci: build for fork ([`1f74ae2`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/1f74ae20c964caea7b0b01eabe64027153c08e0b)) + +### Fix + +* fix(Wikilinks): Removing slug in wiki seems to repear my links problem ([`9c3665c`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/9c3665c6657f6956f06668bde131c4ee8320272f)) + +### Style + +* style(black): Using black is good for reading ([`46c6519`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/46c6519961bffa703990679eb5eff799f3315931)) + +### Unknown + +* Prepare release 0.1.14 (#39) ([`508c0d3`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/508c0d399428f0d7ae596881900aa11baf508526)) + +* Fix Windows builds, and fix nested rel paths (#38) + +* Resolves Github Issue #35 + +* Fixes path searching on Windows machines ([`b147d5f`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/b147d5f33dd937e34a28a0e0f40b58dd43b5d9f3)) + +* Add support for Reference Link definitions (#32) + +* Addresses Github Issue #31, which is a feature request for supporting + Reference Link format links. ([`c4deab4`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/c4deab447beb482da4897a7986ce99f10e4cf0f3)) + +* Release 0.12.0 (#30) + +* Fixes issue #25, `Absolute links not using http:// or https:// are treated as relative`. + +* Fixes issue #27, `Dictionary file cache is not being leveraged`. ([`bee614f`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/bee614f08b3c2d8684231f714d6bf9b1c59832bf)) + +* Fix fast file cache reduction (#29) + +* Previously, an attempt was made to speed up the most naive case of + EzLink conversion, where there is a unique filename across the entire + site. This would allow a simple dictionary lookup instead of a full + Prefix Trie search (which is more expensive). + + Previously, it incorrectly trimmed _all_ files from the file cache + when reducing it to unique items, because the dictionary comprehension + had an inverted comparison operator. + + Now, unique file names will be directly converted via the fast file + cache. ([`66a508d`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/66a508d53958c8a1261f7a44be6ff44b036a452d)) + +* Treat any link containing protocol scheme as ext (#28) + +* This expands the existing behavior of ignoring `http://` and `https://` + schemes (which _were_ hardcoded into the regex) with a greedier Regex + that rejects any link that contains any valid protocol scheme in the + link. + + A big thanks to @robbcrg for the bug report as well as a proof of concept + PR! ([`1e63c84`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/1e63c84f346432dd41745eaf3442cbc02c42fc8c)) + +* Release 0.1.11 (#23) + +* Prevent direct links from searching for file + +* In the change from a dictionary lookup to a trie search + method, it broke direct linking in a subtle way. The links + would ultimately be rendered correctly, however, it required + even direct links to go through the file search process, which + made things less efficient than it should be. + + Now, direct links are detected & applied directly. + +* Improved efficiency of the searching algorithm, leveraging + a direct file name lookup in a dictionary for files that + have a unique name across the site. This should prevent + the less efficient, disambiguating trie search in the naive + case where there are unique files. ([`c924471`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/c924471192bee0cdb996d6585fa52bb05bd7e182)) + +* Fix functional relative links and add auto-disambiguation + +Implement auto-disambiguation and bugfix + + * This fixes a bug in the previous search strategy that missed + allowing for local relative links (something like index.md + referring to about.md in the same subdirectory). + + * It also adds a bit further auto-disambiguation. By this, + I mean it will attempt to find the _closest_ match in proximity + (with respect to the folder hierarchy). For instance, + if this is the layout: + + ``` + + guide/ + + test.md + + getting_started/ + + index.md + + tutorials/ + - test.md + + getting_started/ + + index.md + + more_advanced/ + + index.md + ``` + If you placed a link inside `guide/getting_started/index.md` + such as `[Test](test)`, the resulting link has ambiguity, but + in the default case, the `guide/test.md` file is _closer_ than + the `tutorials/test.md`, therefore, it will select that file. + + You can still further disambiguate the link if desired, but + this provides a bit more sane defaults. ([`66c05f4`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/66c05f49d4216cab0edf38c53d583f31b8fdf816)) + +* [release-0.1.9] Support EzLink path-component based disambiguation (#20) + +* Update file searching to support partial paths + +* This feature switches from using a dictionary to a prefix + trie, caching the files in reverse order (path wise), + which allows for: + + ``` + + folder1/ + - index.md + + folder2/ + - index.md + ``` + +You can now link to `folder1/index.md` and `folder2/index.md`, or +`folder1/index` and `folder2/index`. This allows disambiguating +duplicate filenames from separate unique paths. + +This works across all link types supported by EzLinks. + +Resolves: #18 + +* Finishing touches + +* Adds a number of additional test links, which leverage both + link types. + +* Add documentation on the new feature. + +* Adds a configuration option to control whether EzLinks warns + or simply prints a debug log message when it encounters link + ambiguities. ([`249c838`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/249c83856d24f5af4b121b057716ce80a44fe200)) + +* Bump version number ([`61ba1b4`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/61ba1b48cf77dcaa67b2bfdc1419106adf41e602)) + +* Fixes issue with multiple links on a single line (#17) + +* If there was more than a single MD link on a single line in + a page, the Regex would capture too aggressively, ending up + with a broken capture + +* Adds some tests for single line with multiple links + +Resolves: #16 ([`6aee4f8`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/6aee4f8abccce4266a45b07966e7f432f496c7a1)) + +* Bump version number ([`dc11350`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/dc113503ebc4f5b9dd4ca3c6b2899f18e4f37b5c)) + +* Fix compat with python 3.6 (#15) + +Fixes a couple of language constructs that did not exist in Python 3.6, which is the advertised minspec for this project. I have now made the fixes required to work using Python 3.6. + +Resolves: #14 ([`3f46e7e`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/3f46e7eb111327ac0bb2c4bd79c3fdb528fee02d)) + +* Update release version ([`435a250`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/435a25010a83ca02b39a9b90b97ca35bd19d8958)) + +* Bugfix/issue 12 (#13) + +Various fixes spawing from issues reported in #12 + +* Do not scan external links with an http:// or https:// prefix, + which will prevent properly formatted external links from + emitting a warning for a missing link target. + +* Includes an __init__.py for the mkdocs_ezlinks_plugin/scanners + module, which then is included into the distribution. + +* Also downgrades some prior warnings to debug level, + as most of the messages trigger existing mkdocs warnings + (such as broken link warnings, etc.) + +* Messages are now automatically filtered based on the + '--quiet' and '--verbose' mkdocs flags. + +* Update `Configuration Options` in README.md ([`7297d10`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/7297d10b9c3f7e193c344150ec59c19fa84f03e4)) + +* Bump version number (#11) ([`c86ac23`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/c86ac23ad452893b5c81f26e7f4383dd15008739)) + +* Significant refactor (#10) + +* Significant refactor + +This change aims to extract the major components from the plugin +file, and into more modular, single responsibility classes. + +* Introduces the FileMapper, which provides an interface for building + the file name lookup, as well as searching for said mapped files + +* Introduces the EzLinksReplacer, which was all non-mkdoc specific + functionality from plugin.py + +* Introduces a link scanner pattern, a simple chain of responsibility + for matching a link pattern, and extracting the links from that + link type + +* All link patterns generate the same link information, which allows + all link types to funnel through the same processing, regardless of + how they were extracted. + +* Also removes the 'absolute' option, as I believe it should always be + true. + +* Update README + +* Few bugfixes + +* Remove absolute option from EzLinksOptions + +* Fix WikiLink scanning: + Allow an empty link target if an anchor is specified (similar to + an md link without a target, but with an anchor. This allows for + valid in-page linking (based on section headings) ([`5da1551`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/5da1551cb70f333c9aa028ba7f8ee9ecc73414a8)) + +* Add new feature descriptions to README.md ([`49a8e61`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/49a8e61b794b5fe95d8c83daddcd3c39268bff58)) + +* Update version ([`df5c1c0`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/df5c1c0a9af6c9185bdcdee6bf56ff9b43a8675c)) + +* Preserve code blocks (#8) + +* Don't scan any link patterns inside of fence blocks, both inline, and multiline. + +* Refactor the regex patterns to leverage the +re.X (verbose) flag, which ignores whitespace within the pattern. + +* Various PEP-8 formatting fixes (though not all!) ([`10e2b21`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/10e2b21ac2b243726422f88e70c1ef1f4391a718)) + +* Create python-publish.yml + +Enable PyPi Publish on Release Action ([`b2dde97`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/b2dde971e71b3e8388416eae44c0f492e5737c7b)) + +* Add Logo ([`cc5a085`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/cc5a0855bc3ef5a64fec0484dfb5dc9dc4d59b3a)) + +* Fix readme (#7) + +* Fix Readme ([`4deaeba`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/4deaeba455e3ec79611eb05d07209f7316642573)) + +* Merge pull request #6 from orbikm/release/0.1.3 + +Merge release/0.1.3 back to main ([`13ff4a8`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/13ff4a87a458bb4777ae9d649fda8cbc23e9bf79)) + +* Bump version to 0.1.3 ([`707c2e6`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/707c2e6f1b20b503f314f9dd73e56f6ad95e10f5)) + +* Merge pull request #5 from orbikm/feature/add_title_support + +Add Title support for links ([`e312a0a`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/e312a0ade7937694230abfcfd83c8ccb30e18718)) + +* Add Title support for links + +* Added new link component `title`: + `[Alt Text](page.md#anchor "Title")` + +* WikiLinks will use the Link Text for the title, allowing + you to set image titles using WikiLinks like so: + `[[Image|My Title]]` + +* Fixes #4 + +* BugFix: Support same page Anchors (Fixes #3) + +* BugFix: Move test folder out of PyPi package (hopefully) ([`94c4ff2`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/94c4ff265a3f970a5c0260faf14d4598e24a42d8)) + +* Merge pull request #2 from orbikm/release/0.1.2 + +Merge changes from release/0.1.2 ([`f1f3e7b`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/f1f3e7bf2f5bed25c854099eedd61de187a68c7d)) + +* Bump version ([`7eb5aa2`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/7eb5aa27b6f9bd67e6a11433029784ace2d1cbb2)) + +* Merge pull request #1 from orbikm/release/0.1.1 + +Merge back Release Hotfixes ([`275b6b6`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/275b6b6a86663ab85292b24a303cf38a22e6ca37)) + +* Update README.md ([`c5b870c`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/c5b870c8103dc6b6694e26321a9c5b8df9c2c1d1)) + +* Stop processing theme files + +* Only capture non-theme files in the filename map. ([`e98764c`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/e98764ccf3973d120b914c22db447b6cc105cba2)) + +* Stop processing theme files + +* Only capture non-theme files in the filename map. ([`edd8a0e`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/edd8a0e3e1d4d2d63934679be8829e832873b204)) + +* Update README ([`83836a3`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/83836a370c73fdc6f9d77bb75ab178fb1cb1ed9f)) + +* Add support for no ext and ext specific links ([`faf626d`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/faf626d5fd43cbb3ed38e916729e3efc0cb2c9cb)) + +* Move test under plugin ([`4e53461`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/4e53461c93449d8c6bb480f1b1bb8247beadfb22)) + +* Enable support for wikilinks + +* Fix bug with multiple search pattern building + +* Refactored the way links are built and fed data from the md + and wikilinks style capture groups. This led to a unified search + technique, regardless of which style of link it originates from. ([`d92c3ab`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/d92c3ab2d19dfb9bb7366fd35010423549b56c2e)) + +* Initial Commit ([`69709b4`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/69709b474d001c87cbe0e64ba6408cf2d5783d0a)) + +* Update README.md ([`8f4b519`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/8f4b51939e7a48aa3dc1d6854e92f3b4089f3953)) + +* Initial commit ([`bd6869d`](https://github.com/Lisandra-dev/mkdocs-ezlinked-plugin/commit/bd6869d55c9283a1f6a4e986be889826ed16d586)) diff --git a/README.md b/README.md index 458a826..0a1fc4a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +*Fork* +To install this fork : +`pip install mkdocs-ezlinked-plugin` + # mkdocs-ezlinks-plugin ![](logo.png) diff --git a/mkdocs_ezlinks_plugin/file_mapper.py b/mkdocs_ezlinks_plugin/file_mapper.py index ab53d9f..08e2aa0 100644 --- a/mkdocs_ezlinks_plugin/file_mapper.py +++ b/mkdocs_ezlinks_plugin/file_mapper.py @@ -1,4 +1,4 @@ -import os +import posixpath from typing import List import pygtrie @@ -24,17 +24,17 @@ def __init__( self.files = [file for file in files if root in file.abs_src_path] for file in self.files: - self._store_file(file.src_path) + self._store_file(file.src_uri) def _store_file(self, file_path): # Treat paths as posix format, regardless of OS file_path = file_path.replace('\\', '/') # Store the pathwise reversed representation of the file with and # without file extension. - search_exprs = [file_path, os.path.splitext(file_path)[0]] + search_exprs = [file_path, posixpath.splitext(file_path)[0]] for search_expr in search_exprs: # Store in fast file cache - file_name = os.path.basename(search_expr) + file_name = posixpath.basename(search_expr) if file_name not in self.file_cache: self.file_cache[file_name] = [file_path] else: @@ -52,18 +52,18 @@ def search(self, from_file: str, file_path: str): abs_to = file_path # Detect if it's an absolute link, then just return it directly if abs_to.startswith('/'): - return os.path.join(self.root, abs_to[1:]) + return posixpath.join(self.root, abs_to[1:]) else: # Check if it is a direct link first - from_dir = os.path.dirname(from_file) - if os.path.exists(os.path.join(self.root, from_dir, file_path)): - return os.path.join(self.root, from_dir, file_path) + from_dir = posixpath.dirname(from_file) + if posixpath.exists(posixpath.join(self.root, from_dir, file_path)): + return posixpath.join(self.root, from_dir, file_path) # It's an EzLink that must be searched - file_name = os.path.basename(file_path) + file_name = posixpath.basename(file_path) # Check fast file cache first - if os.path.basename(file_name) in self.file_cache: + if posixpath.basename(file_name) in self.file_cache: abs_to = self.file_cache[file_name][0] else: search_for = list(file_path.split('/')) @@ -82,7 +82,7 @@ def search(self, from_file: str, file_path: str): # an iterative ascent of the link file's path. In this way, we should # be able to get the result closest to the file doing the linking if has_ambiguity: - file_path = os.path.dirname(from_file) + file_path = posixpath.dirname(from_file) components = file_path.split('/') components.reverse() for path_component in components: @@ -105,4 +105,4 @@ def search(self, from_file: str, file_path: str): f"File: '{from_file}'\n" f"Link: '{search_for}'\n" "Ambiguities:\n" + ambiguities) - return os.path.join(self.root, abs_to) + return posixpath.join(self.root, abs_to) diff --git a/mkdocs_ezlinks_plugin/plugin.py b/mkdocs_ezlinks_plugin/plugin.py index a6aaf72..24acd0c 100644 --- a/mkdocs_ezlinks_plugin/plugin.py +++ b/mkdocs_ezlinks_plugin/plugin.py @@ -2,7 +2,6 @@ from typing import List import mkdocs -from mkdocs.utils import warning_filter from .file_mapper import FileMapper from .replacer import EzLinksReplacer @@ -12,7 +11,6 @@ from .types import EzLinksOptions LOGGER = logging.getLogger(f"mkdocs.plugins.{__name__}") -LOGGER.addFilter(warning_filter) class EzLinksPlugin(mkdocs.plugins.BasePlugin): @@ -55,4 +53,4 @@ def on_files(self, files: List[mkdocs.structure.files.File], config): self.init(config) def on_page_markdown(self, markdown, page, config, **kwargs): - return self.replacer.replace(page.file.src_path, markdown) + return self.replacer.replace(page.file.src_uri, markdown) diff --git a/mkdocs_ezlinks_plugin/replacer.py b/mkdocs_ezlinks_plugin/replacer.py index ac27b39..6e28434 100644 --- a/mkdocs_ezlinks_plugin/replacer.py +++ b/mkdocs_ezlinks_plugin/replacer.py @@ -1,4 +1,4 @@ -import os +import posixpath import re from typing import Match from urllib.parse import quote @@ -52,7 +52,7 @@ def compile(self): ''', re.X | re.MULTILINE) def _do_replace(self, match: Match) -> str: - abs_from = os.path.dirname(os.path.join(self.root, self.path)) + abs_from = posixpath.dirname(posixpath.join(self.root, self.path)) try: for scanner in self.scanners: if scanner.match(match): @@ -65,7 +65,7 @@ def _do_replace(self, match: Match) -> str: # Handle case of local page anchor if not link.target: if link.anchor: - link.target = os.path.join(self.root, self.path) + link.target = posixpath.join(self.root, self.path) else: raise BrokenLink(f"No target for link '{match.group(0)}'") else: @@ -78,7 +78,7 @@ def _do_replace(self, match: Match) -> str: raise BrokenLink(f"'{link.target}' not found.") link.target = search_result - link.target = quote(os.path.relpath(link.target, abs_from)) + link.target = quote(posixpath.relpath(link.target, abs_from)) return link.render() except BrokenLink as ex: # Log these out as Debug messages, as the regular mkdocs diff --git a/mkdocs_ezlinks_plugin/scanners/md_link_scanner.py b/mkdocs_ezlinks_plugin/scanners/md_link_scanner.py index b284c5a..f5890b4 100644 --- a/mkdocs_ezlinks_plugin/scanners/md_link_scanner.py +++ b/mkdocs_ezlinks_plugin/scanners/md_link_scanner.py @@ -1,11 +1,12 @@ -from typing import Pattern, Match +import re +from typing import Match from .base_link_scanner import BaseLinkScanner -from ..types import EzLinksOptions, Link +from ..types import Link, BrokenLink class MdLinkScanner(BaseLinkScanner): - def pattern(self) -> Pattern: + def pattern(self) -> str: # +------------------------------+ # | MD Link Regex Capture Groups | # +-------------------------------------------------------------------------------------+ @@ -18,8 +19,7 @@ def pattern(self) -> Pattern: # | md_anchor | Contains the anchor, if present (e.g. `file.md#anchor`) | # | md_title | Contains the title, if present (e.g. `file.md "My Title"`) | # +-------------------------------------------------------------------------------------+ - return \ - r''' + return r""" (?: (?P\!?)\[\] | @@ -36,17 +36,18 @@ def pattern(self) -> Pattern: (?:\ \"(?P[^\"\)]*)\")? ) \) - ''' + """ def match(self, match: Match) -> bool: - return bool(match.groupdict().get('md_target')) + return bool(match.groupdict().get("md_target")) def extract(self, match: Match) -> Link: groups = match.groupdict() + image = groups.get("md_is_image") or groups.get("md_alt_is_image") or "" return Link( - image=groups.get('md_is_image') or groups.get('md_alt_is_image') or '', - text=groups.get('md_text') or '', - target=groups.get('md_filename') or '', - title=groups.get('md_title') or '', - anchor=groups.get('md_anchor') or '' + image=image, + text=groups.get("md_text") or "", + target=groups.get("md_filename") or "", + title=groups.get("md_title") or "", + anchor=groups.get("md_anchor") or "", ) diff --git a/mkdocs_ezlinks_plugin/scanners/reference_link_scanner.py b/mkdocs_ezlinks_plugin/scanners/reference_link_scanner.py index d90bf03..32ab2b3 100644 --- a/mkdocs_ezlinks_plugin/scanners/reference_link_scanner.py +++ b/mkdocs_ezlinks_plugin/scanners/reference_link_scanner.py @@ -4,7 +4,7 @@ class ReferenceLinkScanner(BaseLinkScanner): - def pattern(self) -> Pattern: + def pattern(self) -> str: # +--------------------------------------+ # | Reference Link Regex Capture Groups | # +--------------------------------------+ @@ -14,7 +14,7 @@ def pattern(self) -> Pattern: # | url: Required | # | title: Optional, up to one newline | # +--------------------------------------+ - return r''' + return r""" (?: \[ (?P[^\]]+) @@ -24,20 +24,19 @@ def pattern(self) -> Pattern: (?P\/?[^\#\ \)(\r\n|\r|\n)]*)? (?:\#(?P [^\(\ ]*)?)? (?:(\r\n|\r|\n)?)?(?P\ ?\"[^(\r\n|\r|\n)\"]*\")? - ''' + """ def match(self, match: Match) -> bool: return bool( - match.groupdict().get('ref_text') and - match.groupdict().get('ref_target') + match.groupdict().get("ref_text") and match.groupdict().get("ref_target") ) - def extract(self, match: Match) -> bool: + def extract(self, match: Match) -> Link: groups = match.groupdict() return Link( image=False, - text=groups.get('ref_text') or '', - target=groups.get('ref_target') or '', - title=groups.get('ref_title') or '', - anchor=groups.get('ref_anchor') or '' + text=groups.get("ref_text") or "", + target=groups.get("ref_target") or "", + title=groups.get("ref_title") or "", + anchor=groups.get("ref_anchor") or "", ) diff --git a/mkdocs_ezlinks_plugin/scanners/wiki_link_scanner.py b/mkdocs_ezlinks_plugin/scanners/wiki_link_scanner.py index c5db871..6397032 100644 --- a/mkdocs_ezlinks_plugin/scanners/wiki_link_scanner.py +++ b/mkdocs_ezlinks_plugin/scanners/wiki_link_scanner.py @@ -15,48 +15,41 @@ def pattern(self) -> str: # | wiki_anchor | Contains the anchor, if present (e.g. file.md#anchor -> 'anchor') | # | wiki_text | Contains the text of the link. | # +------------------------------------------------------------------------------------+ - return \ - r''' + return r""" (?P[\!]?) \[\[ (?P[^#\|\]]*?) (?:\#(?P[^\|\]]+)?)? (?:\|(?P[^\]]+)?)? \]\] - ''' + """ def match(self, match: Match) -> bool: groups = match.groupdict() - return groups.get('wiki_link') or groups.get('wiki_anchor') + return groups.get("wiki_link") or groups.get("wiki_anchor") def extract(self, match: Match) -> Link: groups = match.groupdict() - image = groups.get('wiki_is_image') or '' - link = groups.get('wiki_link') or '' - anchor = groups.get('wiki_anchor') or '' - text = groups.get('wiki_text') or link or anchor + image = groups.get("wiki_is_image") or "" + link = groups.get("wiki_link") or "" + anchor = groups.get("wiki_anchor") or "" + text = groups.get("wiki_text") or link or anchor if not (link or text or anchor): - raise BrokenLink(f"Could not extract required field `wiki_link` from {match.group(0)}") + raise BrokenLink( + f"Could not extract required field `wiki_link` from {match.group(0)}" + ) - link = self._slugify(link) if anchor: anchor = self._slugify(anchor) - return Link( - image=image, - text=text, - target=link, - title=text, - anchor=anchor - ) + return Link(image=image, text=text, target=link, title=text, anchor=anchor) def _slugify(self, link: str) -> str: # Convert to lowercase slug = link.lower() # Convert all spaces to '-' - slug = re.sub(r'\ ', r'-', slug) + slug = re.sub(r"\ ", r"-", slug) # Convert all unsupported characters to '' - slug = re.sub(r'[^\/^\w\u4e00-\u9fff\- ]', '', slug) return slug diff --git a/mkdocs_ezlinks_plugin/types.py b/mkdocs_ezlinks_plugin/types.py index 71692e5..cfab687 100644 --- a/mkdocs_ezlinks_plugin/types.py +++ b/mkdocs_ezlinks_plugin/types.py @@ -2,11 +2,14 @@ class BrokenLink(Exception): + #Ignore these pass + @dataclass class Link: - ''' Dataclass to hold the contents required to form a complete Link. ''' + """Dataclass to hold the contents required to form a complete Link.""" + image: bool text: str target: str @@ -15,16 +18,17 @@ class Link: # Render as a complete MD compatible link def render(self): - img = '!' if self.image else '' - anchor = f"#{self.anchor}" if self.anchor else '' - title = f' "{self.title}"' if self.title else '' + img = "!" if self.image else "" + anchor = f"#{self.anchor}" if self.anchor else "" + title = f' "{self.title}"' if self.title else "" return f"{img}[{self.text}]({self.target}{anchor}{title})" @dataclass class EzLinksOptions: - ''' Dataclass to hold typed options from the configuration. ''' + """Dataclass to hold typed options from the configuration.""" + wikilinks: bool warn_ambiguities: bool - reference_links: bool \ No newline at end of file + reference_links: bool diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..60fb1ef --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +mkdocs +dataclasses>=0.7; python_version < "3.7.0" +pygtrie==2.* diff --git a/setup.cfg b/setup.cfg index b88034e..75088e5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,5 @@ [metadata] description-file = README.md +[semantic_release] +version_variable = setup.py:version +branch=main diff --git a/setup.py b/setup.py index 7032833..90ea3c6 100644 --- a/setup.py +++ b/setup.py @@ -1,40 +1,36 @@ from setuptools import setup, find_packages -description = 'A mkdocs plugin that makes linking to other documents easy.' +description = "A mkdocs plugin that makes linking to other documents easy." long_description = description -with open("README.md", 'r') as f: - long_description = f.read() +version="0.3.3" +with open("README.md", "r") as f: + long_description = f.read() +with open("requirements.txt", "r") as f: + required=f.read().splitlines() setup( - name='mkdocs-ezlinks-plugin', - version='0.1.14', - description=description, - long_description=long_description, - long_description_content_type='text/markdown', - keywords='mkdocs', - url='https://github.com/orbikm/mkdocs-ezlinks-plugin', - download_url='https://github.com/orbikm/mkdocs-ezlinks-plugin/archive/v_0.1.14.tar.gz', - author='Mick Orbik', - author_email='mick.orbik@gmail.com', - license='MIT', - python_requires='>=3.6', - install_requires=[ - 'mkdocs>=1.1.0', - 'dataclasses>=0.7; python_version < "3.7.0"', - 'pygtrie==2.*' - ], - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Intended Audience :: Information Technology', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3 :: Only' - ], - packages=find_packages(exclude=['test.*']), - entry_points={ - 'mkdocs.plugins': [ - 'ezlinks = mkdocs_ezlinks_plugin.plugin:EzLinksPlugin' - ] - } + name="mkdocs-ezlinked-plugin", + version=version, + description=description, + long_description=long_description, + long_description_content_type="text/markdown", + keywords="mkdocs, wikilinks, ezlinks, obsidian, roam", + url="https://github.com/Mara-Li/mkdocs-ezlinks-plugin", + author="Mara-Li", + author_email="Mara-Li@outlook.fr", + license="MIT", + python_requires=">=3.6", + install_requires=required, + classifiers=[ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + ], + packages=find_packages(exclude=["test.*"]), + entry_points={ + "mkdocs.plugins": ["ezlinks = mkdocs_ezlinks_plugin.plugin:EzLinksPlugin"] + }, ) diff --git a/test/docs/index.md b/test/docs/index.md index 9ae79f5..d3a1e77 100644 --- a/test/docs/index.md +++ b/test/docs/index.md @@ -1,3 +1,7 @@ Welcome, world! -![[Puppy]] \ No newline at end of file +![[Puppy]] + +![](Puppy.md) + +