azu / gitbook-plugin-include-codeblock

GitBook plugin for including file
Other
40 stars 25 forks source link

Translate filename extensions to language names. #6

Closed joekain closed 8 years ago

joekain commented 8 years ago

Some language's names don't exactly match their filename extensions. One example is Elixir. This change adds a translation function that maps extensions to language names using an associative array. Currently, the array only translate Elixir extensions. Languages not included in the array use the extension as the language name as they did before this change.

joekain commented 8 years ago

Hi, thanks for creating include-codeblock. I've found it incredibly useful for a book I'm writing on the Elixir language. The only problem that I've had is that Elixir files have extensions .ex or .exs so they need some massaging in order to get the right language name for the syntax highlighting. I've made this quick change to handle this.

I've written a test, which passes. But, I haven't been able to test this change within my gitbook build. Is there a way to install my local package and test this completely?

Thanks, Joseph Kain

azu commented 8 years ago

@joekain Thanks for pull request.

Is there a way to install my local package and test this completely?

https://github.com/GitbookIO/gitbook/issues/393

cd your_book
npm install /your/local/path/to/gitbook-plugin-include-codeblock
# or npm link
gitbook serve

It seem to work.

2016-01-11 14-57-08

azu commented 8 years ago

I think that we should use following module insteadof translation map.

https://github.com/Elixirdoc/ext-map-lang/ https://github.com/blakeembrey/language-map

joekain commented 8 years ago

@azu, I've been able to test with my book. Thanks for helping me with that!

I'll try out those modules and will update the pull request.

joekain commented 8 years ago

@azu, I ended up using the language-map package but not the ext-map-lang package. Actually, I recreated most of the ext-map-lang package in the function lookupLanguageByExtension but fixed a bug in the process. Let me know if you would prefer that I make a pull-request to ext-map-lang and then use that package.

joekain commented 8 years ago

Oh, also I should note that this changes the behavior of the plugin slightly. For javascript it now generates "javascript" instead of "js" in the code block. Both highlight correctly.

azu commented 8 years ago

I recreated most of the ext-map-lang package in the function lookupLanguageByExtension but fixed a bug in the process.

OK. It looks good! I will merge this after wait for response to above comment :)

joekain commented 8 years ago

@azu, yes you are right about path.extname(). I'm still learning Javascript, thanks for your help with that. I've updated the pull-request.

azu commented 8 years ago

@joekain I'v merged and released 1.6.0 :tada:

Thanks.

joekain commented 8 years ago

Great, thanks!