Skip to content

No ref name clobber#673

Merged
deathaxe merged 11 commits intoSublimeText-Markdown:3.1.1from
GiovanH:no-ref-name-clobber
Jan 23, 2022
Merged

No ref name clobber#673
deathaxe merged 11 commits intoSublimeText-Markdown:3.1.1from
GiovanH:no-ref-name-clobber

Conversation

@GiovanH
Copy link
Copy Markdown
Contributor

@GiovanH GiovanH commented Dec 16, 2021

Fixes multiple bugs pointed out in #559, including

  • New references clobbering each other's names
  • References failing to find existing references for their link and generating a new name
  • Duplicate references with the same links and names being added anyway

Resolves #559

@GiovanH GiovanH force-pushed the no-ref-name-clobber branch from 84741a3 to 00776a6 Compare December 16, 2021 08:18
@deathaxe
Copy link
Copy Markdown
Member

deathaxe commented Jan 2, 2022

In the following markdown

  1. select the first line with an inline link
  2. call "convert inline to reference"
# Test 1

[GitHub](https://github.com)

[GitHub](https://github.com)
[GitHub](https://github.com)

Restults in:

# Test 1

[GitHub][]

[GitHub][]
[GitHub](https://github.co[]//github.com
[GitHub]: )

[GitHub]: https

The tests package provides a DereferrablePanelTestCase class which uses an invisible panel as scratch pat, so different tests for real world scenarios of text manipulating functions can be implemented. I already use that to test folding and inserting task list items.

Maybe we should add tests for all new or changed functions step by step, this way.

@GiovanH
Copy link
Copy Markdown
Contributor Author

GiovanH commented Jan 16, 2022

In both master and no-ref-name-clobber, if I convert the first link to a reference, I actually get this:

# Test 1

[GitHub](https://github.com)

[GitHub](https://github.com)
[GitHub](https://github.com)

becomes

# Test 1

[GitHub][]

[GitHub](https://github.com)
[GitHub](https://github.com)

[GitHub]: https://github.com

This bug may be unrelated to what this PR addresses.

Also, I wasn't actually able to see how your test suite works; it looks like pytest, but pytest obviously can't import sublime, so I wasn't sure what the procedure was there and didn't see any documentation in either CONTRIBUTING or tests/README.

@deathaxe
Copy link
Copy Markdown
Member

It's actually Convert All Inline Links to References which is broken. It was the only one visible when selecting the first line from the left to the right.

Animation

Even if it adds duplicates it works in current master.


MDE actually uses UnitTesting for both local tests and CI. It's pytest running in ST's plugin_host to be able to use all its APIs.

You are right, I should somehow write some basic docs about how to use it.

The https://github.com/SublimeText-Markdown/MarkdownEditing/blob/3.1.1/tests/test_reference_completions.py contains a quite minimal example. All the magic is packed into DereferrablePanelTestCase, which provides an invisible output panel, which is used as scratch pad. It provides methods to manipulate text and selections, read content or access self.view directly.


general note:

You should probably rebase your PRs onto the st3176 branch if we want to ship them for ST3 releases as well.

The master branch targets ST4, already.

@deathaxe deathaxe force-pushed the no-ref-name-clobber branch from 826371a to 1c0d76b Compare January 20, 2022 17:20
@deathaxe
Copy link
Copy Markdown
Member

I've rebased your work onto 3.1.1 branch and added a unittest.

Not sure if it's possible, but you might want to change the PR to get it merged into 3.1.1 maybe.

I am also concerned about recent syntax changes might have broken your functionality, because reference definition regions are no longer separated by a newline. Once find_by_selector returned a region, it may need to be parsed and split.

Something along those lines ...

for ref in self.view.find_by_selector("meta.link.reference.def"):
for match in self.re_reflinks.finditer(self.view.substr(ref)):

@deathaxe
Copy link
Copy Markdown
Member

This PR seems to break auto counting of new footnote definitions when calling MarkdownEditing: New Footnote

@GiovanH GiovanH changed the base branch from master to 3.1.1 January 21, 2022 01:33
@GiovanH GiovanH force-pushed the no-ref-name-clobber branch 3 times, most recently from cc4bd5b to ae9ce4a Compare January 21, 2022 01:43
@GiovanH
Copy link
Copy Markdown
Contributor Author

GiovanH commented Jan 21, 2022

I've rebased your work onto 3.1.1 branch and added a unittest.

Not sure if it's possible, but you might want to change the PR to get it merged into 3.1.1 maybe.

I am also concerned about recent syntax changes might have broken your functionality, because reference definition regions are no longer separated by a newline. Once find_by_selector returned a region, it may need to be parsed and split.

Something along those lines ...

for ref in self.view.find_by_selector("meta.link.reference.def"):
for match in self.re_reflinks.finditer(self.view.substr(ref)):

I am concerned about the stability of replacing pure sublime text selectors with just regular expressions. Do we have standard regex defined for the various markdown features, or is the current practice just to write them inline like getMarkers does?

@GiovanH
Copy link
Copy Markdown
Contributor Author

GiovanH commented Jan 21, 2022

Strange. After changing the row numbers to accurately match the data, the tests pass successfully on my machine, but the github test runner is now acting like the cursor is in the wrong place.

@deathaxe
Copy link
Copy Markdown
Member

deathaxe commented Jan 22, 2022

This PR contains 7403454 which is incompatible with ST3 and thus must not be part of it here. That's actually the commit which the st3176 and master branch differ by at the moment.

Actually all my commits up to 918337b must not be here.

@deathaxe deathaxe force-pushed the no-ref-name-clobber branch from 7c8437c to 07cd5fb Compare January 22, 2022 09:19
@deathaxe
Copy link
Copy Markdown
Member

I've dropped the "bad" commits.

Satisfy flake8
@deathaxe deathaxe force-pushed the no-ref-name-clobber branch from b4561c6 to d553e74 Compare January 22, 2022 09:25
@deathaxe
Copy link
Copy Markdown
Member

I somehow start hating black. It produces different output depending on used versions.

@deathaxe deathaxe force-pushed the no-ref-name-clobber branch from a073aa1 to d595f82 Compare January 22, 2022 11:45
@deathaxe
Copy link
Copy Markdown
Member

If you are fine with my hijacked commits, I guess we may be able to merge this PR.

@GiovanH
Copy link
Copy Markdown
Contributor Author

GiovanH commented Jan 22, 2022

Looks good to me.

@deathaxe deathaxe merged commit 7fdb998 into SublimeText-Markdown:3.1.1 Jan 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert inline links to reference link problem - duplicate entries

2 participants