Giter Site home page Giter Site logo

Comments (11)

daledesilva avatar daledesilva commented on May 25, 2024 1

Oh, apologies for the confusion, my function is intended to maintain tag functionality. It turns #1920 into #_1920
Google Keep allows labels of any characters, so this was to enable those labels to convert to hashtags.

from obsidian-importer.

egauthier avatar egauthier commented on May 25, 2024

As you can imagine, this happens a lot! I have a large number of Notes in Evernote with strings like:

from obsidian-importer.

lishid avatar lishid commented on May 25, 2024

Hmm I think tags in the text itself doesn't allow starting with digits because it is quite likely that they are used for numbering things - however for frontmatter this is ok since we are explicitly stating tags.

from obsidian-importer.

claremacrae avatar claremacrae commented on May 25, 2024

In case it helps, here is the write-up of tag validity in the docs:
https://help.obsidian.md/Editing+and+formatting/Tags#Tag+format

In fact, from a user issue in Tasks, I think that #12.3 is also not treated as a valid tag.

from obsidian-importer.

egauthier avatar egauthier commented on May 25, 2024

correct. According to the documentation

Tags must contain at least one non-numerical character. For example, #1984 isn't a valid tag, but [#y1984] is.

Yet after using importer, I have many tags (which I used in Evernote) that are simply numbers. In my case years

foobar

from obsidian-importer.

j-palindrome avatar j-palindrome commented on May 25, 2024

I added some code for the Notion importer to escape most tags, which might be useful here:

export function escapeHashtags(body: string) {
	const tagExp = /#[a-z0-9\-]+/gi;

	if (!tagExp.test(body)) return body;
	const lines = body.split('\n');
	for (let i = 0; i < lines.length; i++) {
		const hashtags = lines[i].match(tagExp);
		if (!hashtags) continue;
		let newLine = lines[i];
		for (let hashtag of hashtags) {
			const hashtagInLink = new RegExp(
				`\\[\\[[^\\]]*${hashtag}[^\\]]*\\]\\]|\\[[^\\]]*${hashtag}[^\\]]*\\]\\([^\\)]*\\)|\\[[^\\]]*\\]\\([^\\)]*${hashtag}[^\\)]*\\)|\\\\${hashtag}`
			);

			if (hashtagInLink.test(newLine)) continue;
			newLine = newLine.replace(hashtag, '\\' + hashtag);
		}
		lines[i] = newLine;
	}
	return lines.join('\n');
}

from obsidian-importer.

claremacrae avatar claremacrae commented on May 25, 2024

Wow, when I see a regex like that, i.e. any non-trivial regex, my first thought is always 'I do hope the project has thorough unit tests, with a wide range of inputs to test the regex really thoroughly...'

from obsidian-importer.

ericaxu avatar ericaxu commented on May 25, 2024

@egauthier Can you check where the tags end up? Are they in the frontmatter tags property?

from obsidian-importer.

egauthier avatar egauthier commented on May 25, 2024

Obsidian: v1.4.1 (installer version 1.2.8)
Importer: v1.0.4

This screenshot is with both hashtag strings in the body and Evernote tags on the Note itself.

Both are added to the global tags. The hashtag strings are not added to the frontmatter, but are added to the Obsidian tag hierarchy. The #123 in the body did not create a tag, presumably because it is not a valid Obsidian tag, but the 1234 Evernote tag did.

Screenshot 2023-07-31 at 2 09 43 PM

from obsidian-importer.

daledesilva avatar daledesilva commented on May 25, 2024

In my pull request for Google Keep import, I actually created a sanitizing function to deal with this when I noticed it happening. Simply putting an underscore before any tags that start with a number.

The PR is still in review, but this function could be used for sanitisation of other hashtags in the future and evolved to work differently if needed.

from obsidian-importer.

j-palindrome avatar j-palindrome commented on May 25, 2024

from obsidian-importer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.