Closed ZigZagT closed 8 years ago
This ttt
you are speaking of, is that just a placeholder, or is it an already existing language?
How this works in either way is that there's a list of recognized languages for the fenced-code-blocks (see here) and if ttt
is an existing language, which has an existing grammar-package (for instance, language-javascript
would be embedded in your second example), it is fairly simple to add it to that list, and from then on the code will be highlighted in your Markdown document.
However, if ttt
doesn't have a grammar yet, you'll have to create one before you (or anybody else) can add it to the list. Writing a grammar from scratch is no easy task though.
Does this help?
I'm using it just as an alias of another language. The fenced-code-blocks is what I need. Thank you very much.
You're welcome.
I just tried that, but it not work at all. I'm not aware about coffee script as well as atom. I'm sorry to troubled you again and again, but please let me know where I went wrong.
cd into /.atom/packages/language-markdown
, and modify the /grammars/fixtures/fenced-code.cson
file:
from:
{ pattern:'javascript|js|jsx', include:'source.js' }
to:
{ pattern:'javascript|js|jsx|ttt', include:'source.js' }
restart atom
Not a problem.
There are some instructions in the README on how the grammar of this package is compiled. The thing with your approach though, is that it will break every time language-markdown
gets updated.
Is your ttt
thing something that would benefit others? If so, I can add it to the main package. That would be the easiest solution for you.
ttt
is just a placeholder. I'm trying to use pure markdown to finish some complex job, for example, build an non-static blog site. So I have to extends the functionality of original markdown. The most suitable appoach is to use custom code block to represent extended fetures. In this case, I want to use
```run
some javascript code with syntax highlight
```
to indicate that this piece of code should will run in the browser through my custom markdown parser, while it also visible in other standard markdown parser.
Recompile the package every time adding an alias (like ttt
or run
) should not a good idea.
I think I know a better already available solution. There's support for, darn it, I forgot the name, something like custom attributes, or special attributes or something. It would look something like this:
```javascript {run}
alert("BadaBing");
```
If you could adapt your custom markdown parser to recognize this pattern (the curly braces notation is often used, in Extra Markdown and R Markdown for instance) then I believe you're all set. It will still be recognized and highlighted as Javascript, and you needn't worry about updates.
Have a look at this spec to get an idea of what else the notation is used for. You could easily extend your own parser with additional functionality if needed.
It look good. I'm trying to make it work.
Let me know how it works out. Bed time over here, so I'll check in again tomorrow. Good luck!
I had checked the r markdown specification and had learn about the knitr engine. And I found these problems:
{javascript }
code block, but I have to insert a whitespace between javascript
and }
. It seems a little bug.'''{r } '''
(for convenience, I'm using ' to replace in this comment) pattern, the prefix
{rshould be a keyword indicates that the R markdown parser should treat this "code block" as an "code chunk". The language used inside the chunk should be specified by the
engineoption. For example,
'''{r engine="javascript"} '''indicates that this code chunk contains javascript code. This is doced [here](http://yihui.name/knitr/demo/engines/). Any code chunk beginning label replaces the
rin
'''{r } '''with other language name, should be an shorthand or the
engineoption. doced [here](http://rmarkdown.rstudio.com/authoring_knitr_engines.html). Language-markdown package seems not supports the
engine` option grammar.R Markdown support is indeed still incomplete, see #93. I've added the trailing space as a bug there, but I have to admit that priority to fully implement R Markdown is not high. A big part of that is the engine
argument you found; I want to avoid having to generate hundreds of lines of code (which would slow down the parser) that only a handful of users use.
Are you thinking of dropping your custom parser in favor of R Markdown? It is an interesting superset of Markdown, but there's a good chance that syntax highlighting within R Markdown blocks won't happen. Can you make your custom parser work with the ```javascript {run}
syntax I suggested?
I had add basic r markdown support for marked, a parser in javascript.
If you have to add it yourself, I still suggest going with the ```javascript {run}
I suggested. The curly braces are more or less an accepted addition to the Markdown syntax, and besides fully supporting R Markdown (which is an investment I'm not willing to make just for this issue) I'm not sure there's anything else I can do for you.
The engin argument is not important in markdown, the
is a little far away of the "standard", i'm trying to avoid this.{js xxx}</code> syntax is enough for me. The <code>
javascript {run}
Well, since ```{js xxx}
works with syntax-highlighting, I think we can close this issue then. Let me know if you run into any other issues.
That's fine, thank you
Where can I find the source.languagename
file if I have already installed the language grammer?
@Edenharder I'm not sure what you are looking for. Could you explain it in a bit more detail? Also, if it is unrelated to this issue, please create a new one.
In the file fenced-code.md, it says that
# Objects in {list} have the following structure:
#
# {
# pattern: {string}
# include: {string}
# contentName: {string}
# }
#
# 'pattern' is required; item is ignored if 'pattern' is missing
# If 'include' is omitted, 'include' will become 'source.'+pattern
# If 'contentName' is omitted, 'contentName' will become 'embedded.'+pattern
If I want to add support for a new language, for example, latex. And I have installed the package language-latex already. Then I need to find out where 'source.latex' is to configure fenced-code.md. But I do not know where it will be usually.
That depends on the language ; )
The source.languagename
you are referring too is the base scope that these grammars use. Atom is essentially a webpage, and this base scope is the css class given to a line that contains code from that particular language. The thing is, it differs for a number of languages.
The easiest way to find this scope is to open the main grammar file for a language (grammars/language-markdown.json in the case of this package) and (usually) near the top of the file you'll see an item named scopeName
, and that's the value you are looking for that you'll need for the include
section of the fenced-code bit. The scopeName for language-latex would be text.tex.latex
.
Latex will be added in an upcoming version though. I've recently added support for inline math, and it's part of that. If you need help with any other languages, feel free to open a new issue, point me to the language-packages, and it should be in the next version.
I'm trying making something like this
and want the code to be highlighted just like well-known language syntax
How can i do it?