MarkdownSnippets icon indicating copy to clipboard operation
MarkdownSnippets copied to clipboard

Re-instate preserving of line endings

Open claremacrae opened this issue 3 years ago • 5 comments

Preamble

Hi Simon, it looks to me like #22 might have got un-fixed at some time.

Here's what's happening...

Describe the bug

A clear and concise description of what the bug is. Include any relevant version information.

On macOS, running:

mdsnippets --version
mdsnippets 24.2.2+78ae4cdf92e0c9f14cb7b822c6464773569e6b56

with this configuration:

{
  "$schema": "https://raw.githubusercontent.com/SimonCropp/MarkdownSnippets/master/schema.json",
  "ExcludeDirectories": [ "node_modules" ],
  "Convention": "InPlaceOverwrite",
  "TocLevel": 5
}

... I find that all my .md files are converted from LF end-of-lines to CRLF

image

I actually don't yet have any snippets or toc lines. I just wanted to make sure that I could run the tool, having not used it for a while.

A clear and concise description of what you expected to happen.

Add any other context about the problem here.

I would like mdsnippets to preserve the line-endings of the input file. It used to do th

Minimal Repro

Ensure you have replicated the bug in a minimal solution with the fewest moving parts. Often this will help point to the true cause of the problem. Upload this repro as part of the issue, preferably a public GitHub repository or a downloadable zip. The repro will allow the maintainers of this project to smoke test the any fix.

Please let me know if you need that.

Submit a PR that fixes the bug

Submit a Pull Request (PR) that fixes the bug. Include in this PR a test that verifies the fix. If you were not able to fix the bug, a PR that illustrates your partial progress will suffice.

Sorry, unable to do that with my current skills.

I looked at the issue #22 to see if it linked to a specific commit, in which case I would have looked through the repo at the history of the relevant lines...

claremacrae avatar Oct 05 '22 16:10 claremacrae

@SimonCropp There is something weird going on. It's not happening now on my Mac. So the answer is that a minimal repro is needed. I'll close this for now, and re-open it if I can figure out what changed...

claremacrae avatar Oct 05 '22 17:10 claremacrae

@claremacrae AFAIK i havnt tweaked anything that should have changed that behaviour. let me know if u want to jump on a call so u can show the the problem

SimonCropp avatar Oct 06 '22 00:10 SimonCropp

Thank you @SimonCropp. I will indeed do that, if I get to the stage that I'm using mdsnippets for real on the project.

(For background, I'm working towards using Approval Tests on this project (TypeScript with Jest test framework), and when that's working, if I still have this problem I'll get back to you. It's embedding markdown samples inside markdown files, which doesn't seem to be playing nicely with mdsnippets - a separate issue.)

claremacrae avatar Oct 10 '22 05:10 claremacrae

@claremacrae AFAIK i havnt tweaked anything that should have changed that behaviour. let me know if u want to jump on a call so u can show the the problem

Hi Simon, I believe I have now normalised all the line endings in my repo, and still mdsnippets is converting all files it processes to CRLF on Mac.

I would love to show you where I've got to. I'll email...

claremacrae avatar Oct 21 '22 08:10 claremacrae

Just in case it helps anyone else here, I've found a series of steps to run mdsnippets that works for my current project, obsidian-tasks:

mdsnippets && yarn run lint:markdown && git add --renormalize .

The two issues the above solves are:

  • the project is configured to use- characters for bullet points
    • mdsnippets processes toc lines and adds list items beginning * - so running yarn run lint:markdown invokes markdownlint-cli2-fix to convert the * to -
    • details of that step are in the project's package.json file
  • on Mac, even with all input files having LF as line endings, mdsnippets writes out files with CRLF endings
    • git add --renormalize . converts them back to LF

claremacrae avatar Nov 23 '22 21:11 claremacrae