问题
I'm struggling to add empty spaces before the string starts to make my GitHub README.md looks something like this:
Right now it looks like this:
I tried adding <br /> tag to fix the new string start, now it works, but I don't understand how to add spaces before the string starts without changing everything to . Maybe there's a more elegant way to format it?
回答1:
You can use <pre> to display all spaces & blanks you have typed. E.g.:
<pre>
hello, this is
just an example
....
</pre>
回答2:
Markdown really changes everything to html and html collapses spaces so you really can't do anything about it. You have to use the for it. A funny example here that I'm writing in markdown and I'll use couple of here.
Above there are some without backticks
回答3:
Markdown gets converted into HTML/XHMTL.
John Gruber created the Markdown language in 2004 in collaboration with Aaron Swartz on the syntax, with the goal of enabling people to write using an easy-to-read, easy-to-write plain text format, and optionally convert it to structurally valid HTML (or XHTML).
HTML is completely based on using for adding extra spaces if it doesn't externally define/use JavaScript or CSS for elements.
Markdown is a lightweight markup language with plain text formatting syntax. It is designed so that it can be converted to HTML and many other formats using a tool by the same name.
If you want to use »
only one space » either use
or just hitSpacebar(2nd one is good choice in this case)more than one space » use
+space (for 2 consecutive spaces)
eg. If you want to add 10 spaces contiguously then you should use
space space space space space
instead of using 10 one after one as the below one
For more details check
- Adding multiple spaces between text in Markdown,
- How to create extra space in HTML or web page.
回答4:
I'm surprised everyone refers to non-breaking spaces ( ) but no one mentioned the HTML entities   and   which produce horizontal white space equivalent to the characters n and m, respectively. If you want to accumulate horizontal white space quickly, those are more efficient.
-
-
  -
 
Along with <space> and  , these are the five entities HTML provides for horizontal white space.
Note, however, that except for , all entities allow breaking, i.e. they will allow whatever content surrounds them to wrap to a new line if otherwise extending beyond the container's edge. Depending on your case, that may be desired or undesired behavior. In my usage, it's usually desired.
回答5:
Instead of using HTML entities like and   (as others have suggested), you can use the Unicode em space (8195 in UTF-8) directly. Try copy-pasting the following into your README.md. The spaces at the start of the lines are em spaces.
The action of every agent <br />
into the world <br />
starts <br />
from their physical selves. <br />
回答6:
As a workaround, you can use a code block to render the code literally. Just surround your text with triple backticks ```. It will look like this:
2018-07-20 Wrote this answer
Can format it without
Also don't need <br /> for new line
Note that using <pre> and <code> you get slightly different behaviour:   and <br /> will be parsed rather than inserted literally.
<pre>:
2018-07-20 Wrote this answer
Can format it without
Also don't need
for new line
<code>:
2018-07-20 Wrote this answer
Can format it without
Also don't need
for new line
来源:https://stackoverflow.com/questions/44810511/how-to-add-empty-spaces-into-md-markdown-readme-on-github