├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── lib ├── hexo-renderer-mathjax.js └── mathjax.html ├── package.json ├── sample.png └── test └── hexo-renderer-mathjax-test.js /.gitignore: -------------------------------------------------------------------------------- 1 | ### Node template 2 | # Logs 3 | logs 4 | *.log 5 | npm-debug.log* 6 | 7 | # Runtime data 8 | pids 9 | *.pid 10 | *.seed 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 19 | .grunt 20 | 21 | # node-waf configuration 22 | .lock-wscript 23 | 24 | # Compiled binary addons (http://nodejs.org/api/addons.html) 25 | build/Release 26 | 27 | # Dependency directory 28 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 29 | node_modules 30 | 31 | # Created by .ignore support plugin (hsz.mobi) 32 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git* 2 | .DS_Store 3 | *.png 4 | *.jpg -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | 4 | node_js: 5 | - "0.10" 6 | - "0.11" 7 | - "0.12" 8 | - "4" 9 | - "5" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Phoenixcw 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MathJax Renderer Plugin for Hexo 2 | 3 | [![npm version][npm-badge]][npm-url] 4 | [![Build Status][travis-badge]][travis-url] 5 | [![Coverage Status][coveralls-badge]][coveralls-url] 6 | [![Dependency Status][david-badge]][david-url] 7 | 8 | Add support of [MathJax](http://www.mathjax.org/) for [Hexo](http://hexo.io/). 9 | 10 | ## INSTALL 11 | 12 | $ npm install hexo-renderer-mathjax --save 13 | 14 | Edit `_config.yml`: 15 | 16 | plugins: 17 | - hexo-renderer-mathjax 18 | 19 | ## Sample 20 | 21 | Write the following latex code: 22 | 23 | $$ 24 | \frac{\partial u}{\partial t} = h^2 \left( \frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} + \frac{\partial^2 u}{\partial z^2}\right) 25 | $$ 26 | 27 | Then you will get: 28 | 29 | ![sample](https://raw.githubusercontent.com/phoenixcw/hexo-renderer-mathjax/master/sample.png) 30 | 31 | [npm-badge]: https://badge.fury.io/js/hexo-renderer-mathjax.svg 32 | [npm-url]: https://badge.fury.io/js/hexo-renderer-mathjax 33 | [travis-badge]: https://api.travis-ci.org/phoenixcw/hexo-renderer-mathjax.svg 34 | [travis-url]: https://travis-ci.org/phoenixcw/hexo-renderer-mathjax 35 | [coveralls-badge]:https://coveralls.io/repos/phoenixcw/hexo-renderer-mathjax/badge.svg?branch=master&service=github 36 | [coveralls-url]: https://coveralls.io/github/phoenixcw/hexo-renderer-mathjax?branch=master 37 | [david-badge]: https://david-dm.org/phoenixcw/hexo-renderer-mathjax.svg 38 | [david-url]: https://david-dm.org/phoenixcw/hexo-renderer-mathjax -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | require('./lib/hexo-renderer-mathjax'); -------------------------------------------------------------------------------- /lib/hexo-renderer-mathjax.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var ejs = require('ejs'); 3 | var fs = require('hexo-fs'); 4 | 5 | var layout = 'layout.ejs'; 6 | var bodyTag = ''; 7 | var mathjaxScript = fs.readFileSync(path.join(__dirname, 'mathjax.html')); 8 | 9 | hexo.extend.renderer.register('ejs', 'html', function(data, options) { 10 | var path = options.filename = data.path; 11 | var content = data.text; 12 | if (layout === path.substring(path.length - layout.length)) 13 | content = content.replace(bodyTag, mathjaxScript + '\n' + bodyTag); 14 | ejs.render(content, options); 15 | }); 16 | -------------------------------------------------------------------------------- /lib/mathjax.html: -------------------------------------------------------------------------------- 1 | 15 | 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hexo-renderer-mathjax", 3 | "version": "0.6.0", 4 | "description": "MathJax renderer plugin for Hexo", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha", 8 | "coverage": "istanbul cover _mocha; cat coverage/lcov.info | coveralls" 9 | }, 10 | "dependencies": { 11 | "ejs": "^2.3.4" 12 | }, 13 | "devDependencies": { 14 | "chai": "^3.4.1", 15 | "coveralls": "^2.11.6", 16 | "ejs": "^2.3.4", 17 | "hexo": "^3.1.1", 18 | "hexo-fs": "^0.1.5", 19 | "istanbul": "^0.4.1", 20 | "mocha": "^2.3.4" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/phoenixcw/hexo-renderer-mathjax.git" 25 | }, 26 | "keywords": [ 27 | "math", 28 | "mathjax", 29 | "renderer", 30 | "hexo" 31 | ], 32 | "author": { 33 | "name": "phoenixcw", 34 | "email": "ariosxcw@hotmail.com", 35 | "url": "http://blog.phoenixcw.com" 36 | }, 37 | "readme": "https://github.com/phoenixcw/hexo-renderer-mathjax/blob/master/README.md", 38 | "license": "MIT", 39 | "bugs": { 40 | "url": "https://github.com/phoenixcw/hexo-renderer-mathjax/issues" 41 | }, 42 | "homepage": "https://github.com/phoenixcw/hexo-renderer-mathjax" 43 | } 44 | -------------------------------------------------------------------------------- /sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phoenixcw/hexo-renderer-mathjax/bb79efdc8378c7e8bf6dcea5214b5a0e9d84eb96/sample.png -------------------------------------------------------------------------------- /test/hexo-renderer-mathjax-test.js: -------------------------------------------------------------------------------- 1 | /*global describe,it*/ 2 | 'use strict'; 3 | 4 | var Hexo = require('hexo'); 5 | global.hexo = new Hexo(__dirname, {silent: true}); 6 | 7 | var expect = require('chai').expect, 8 | should = require('chai').should(); 9 | 10 | // load render 11 | require('../index.js'); 12 | 13 | describe('hexo-renderer-matjax', function() { 14 | 15 | 16 | describe('should register renderer', function() { 17 | it('register category_transform', function() { 18 | var renderer = hexo.extend.renderer; 19 | should.exist(renderer, "render don't exist"); 20 | should.exist(renderer.list(), "no renderer"); 21 | should.not.equal(renderer.list().length, 0, "no renderer"); 22 | should.exist(renderer.get('ejs'), "no ejs renderer"); 23 | }); 24 | }); 25 | 26 | }); 27 | --------------------------------------------------------------------------------