Join GitHub today
Markdown code-block indentation removed when saving as field #1567
When using code blocks in markdown fieldtype the indentation should be retained.
All trailing spaces in a code block are removed when using markdown field set. Manually editing the YAML file works - everything is rendered as it should be. But as soon as you open the page in the control panel and save it the spaces are removed:
The YAML file
Steps to reproduce
Create a fieldset containing markdown.
Paste some code block with indentation.
Operating System: Mac
Web Server: PHP internal
PHP Version: 5.6
Statamic Version: 2.6.4
Updated from an older Statamic or fresh install: From 2.6.3
The problem is located in the spyc YAML dumper and parser: It modifies the data before storing it:
This is something that in my opinion must not happen: I'd expect to get the same data when saving and loading it.
I've tested replacing the YAML module with https://github.com/symfony/yaml and it seems to do a way better job.
Changing YAML.php to use
for writing and parsing with
keeps the Markdown as it's written without destroying the data.
We are aware of the issue in Spyc. See mustangostang/spyc#54
The next version of Statamic will have an updated version of the Markdown parser which has an option for hard line breaks (Github style). If you enable that, you can avoid the requirement for two spaces at the end for a line break. This could be a nice workaround until the Spyc bug is fixed.
@jasonvarga I've seen this isuue - but this one is about parsing the fields. The bug I am refering go is about writing the data. In fact it's mangled twice. The issue is also not describing the problems with lines wrapped in quote marks - which simply get lost, too...
You've submitted this bug 1 year ago to spcy - there was no update, no response - nothing. The last update to the parser was 6 months ago. I would really recommend switching to a better supported and tested component.
As already mentioned: https://github.com/symfony/yaml is well tested, gets regular updates and improvements.
If you don't have a space next to the colon, it throws exceptions. For a platform that can be editing without the control panel, this is a super common occurrence.
Also (and while this is a benefit, it is a breaking change), truthy/falsy rules are quite different.
I'm having the same problem. I'm building a website based around a lot of code blocks (tutorials for students) so it's really annoying.
Could there be an option so you can choose which parser you use? People who have problems with the different syntax could use the older one, and people who use the correct syntax could use the Symfony one?
To clarify, code snippets maintain their indentation when using the main
I've found a workaround for this that involves wrapping the whitespace in quotes: