Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown filename format string allowing e.g. dates, custom replacements #58

Open
dge8 opened this issue Aug 30, 2021 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@dge8
Copy link
Contributor

dge8 commented Aug 30, 2021

The source code includes a polite recognition that replacement of spaces with underscores is simply a personal preference. In my case, I've modified the source code to not replace spaces, and also to not add the replacement underscores in general. Others still likely have their own preferences or requirements.

Feature request: allow providing a format string for filenames at the command-line. This could also allow specifying custom fields (like the creation/modified date, author, or other note attributes) and custom replacements.

Here's one possible format:

Example 1 (current behaviour):
evernote2md --filenameFormat '%title/ /_/%dmacos/_/'

  • filename is the title
  • first replacement replaces spaces with underscores
  • second replacement replaces disallowed macOS filename characters with underscores
  • evernote2md additionally removes any remaining characters disallowed by the current OS, and ensures filenames are unique and non-empty by adding numbers 1, 2, ... as necessary.

Example 2 (my modified behaviour):
evernote2md --filenameFormat '%cdateiso %title/%dany//40'

  • filename is the creation date in ISO format (YYYY-MM-DD) followed by a space, then the title
  • first replacement removes characters disallowed on any platform, with no replacement character
  • filenames are truncated at 40 characters
  • evernote2md additionally removes any remaining characters disallowed by the current OS, and ensures filenames are unique and non-empty by adding numbers 1, 2, ... as necessary.

The logic for processing such a format string would amount to:

  1. splitting the format string into substrings on the / character (which is illegal on all platforms)
  2. performing the field replacements from the note metadata on each of the substrings
  3. set the filename to the first substring
  4. for each remaining pair of substrings, perform a regex replacement (s/<fromstring>/<tostring>/g)
  5. if there is a substring remaining, trim the filename to that number of characters
  6. prefix the destination directory and add .md to the end

This could provide a solution for Issue #57 as well - assuming regexes, %dlinux could be replaced with [/], %dmacos with [:/], %dwin with [\\/:*?"<>|]|([ .]+$) or something similarly convoluted, and %dany a combination of the three, to manually remove characters that would otherwise be permitted on the current platform (although, don't quote me on those exact regexes).

Finally, a stretch goal might be to provide a similar format string for images/media: --resourceFilenameFormat 'image/%resid' for current behaviour or 'assets/%notefilename/image%resindex' to match the requested format in Issue #53. Won't be able to use the forward slash for both directory and replacements though.

Cheers.

@wormi4ok
Copy link
Owner

Hello @dge8,

First of all, I appreciate that you took the time to compile such a detailed feature request. I find the proposal incredible, and the implementation suggestions make total sense to me.

My initial idea was to build a tool that extracts as much information as possible from the Evernote archive and nothing else. Now I see that there is a need to manage those notes. Adapt the exported files to the external tools, OS environment etc.

The first sign was the --folders flag, which changes the layout of the output. It felt wrong to include this flag since it has nothing to do with the content of the notes, and I believe that evernote2md should focus on converting notes, not structuring them.

Now I see that the folder structure of the notes, file names and assets location is important to the people using evernote2md. And I still feel resistant to adding the flags to manipulate filenames, asset paths and platform-specific character escaping.

Following the UNIX way, I'd like evernote2md to do the conversion and do it well. But acknowledging the need in the community, I still believe that there should be a good way to manage the structure of the markdown files.

So I've started a new project called mdmv. The primary purpose of this tool would be markdown files manipulation.
mdmv will rely on the Frontmatter information in the notes and, I hope, it will be helpful to a broader audience as a generic tool to move/rename markdown files and assets retaining correct links.

It will take time to get this tool ready, and there will be breaking changes to evernote2md to split features and make a smooth integration between the two. But I see this as the right move that will help me to keep maintaining the project.


This is the first time I used the word community addressing everyone who spent time reporting bugs and proposing new ideas to the project. I'm delighted that this utility helped so many people, and it inspires me to create more open-source tools.
Thank you all. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants