asciidoctor / asciidoctor-maven-plugin

A Maven plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
http://asciidoctor.org
Apache License 2.0
318 stars 122 forks source link

'pygments' source code highlighting not working #118

Open abelsromero opened 10 years ago

abelsromero commented 10 years ago

Hi,

First, of all I'm not sure it is a bug since the readme says that only coderay and highlightjs are supported. However that, I've been testing the 4 possible options and only Pygments is now working due to the following error:

org.jruby.exceptions.RaiseException: (RuntimeError) asciidoctor: FAILED: required gem 'pygments.rb' is not installed. Processing aborted.

If it's not an error, and some extra configuration is required this could be added to the plugin's readme.

I've written a few tests to validate the cases: https://github.com/abelsromero/asciidoctor-maven-plugin/commit/a42215caf8f02a88fc03a6fa0f2b0e6bc7533ac2

mojavelinux commented 9 years ago

Pygments is not supported with AsciidoctorJ. We recommend that you use CodeRay instead.

We are exploring the possibility of switch to Rouge in Asciidoctor core, which is a Ruby port of Pygments. Since it's pure Ruby, Rouge will work with AsciidoctorJ.

See https://github.com/asciidoctor/asciidoctor/issues/1040.

abelsromero commented 9 years ago

Is there any update regarding the integration of rouge? I tried adding the rouge gems and it fails, which I guess is normal :P

If there're no current plans for it, we could close this issue.

mojavelinux commented 9 years ago

I think the plan moving forward is to support rouge, but we can't do that until it's integrated into core. Until then, this issue should be labeled as "tracking" and scheduled on the milestone "future" (both which need to be created).

mojavelinux commented 9 years ago

Label and milestone updated.

abelsromero commented 9 years ago

Impeccable answer, thanks.

thekalinga commented 5 years ago

Any chance of integrating this?

mojavelinux commented 5 years ago

Rouge should now work (assuming you're using Asciidoctor 2) and is preferred.

Having said that, pygments.rb does now work with JRuby, so it could be loaded onto the classpath.

thekalinga commented 5 years ago

Thanks for that

Is there an example in github thats how to use with Asciidoctor 2? I am currently using 1.5.8 (looks like Asciidoctor 2 is a complete rewrite)

buildscript {
  repositories {
    maven {
      url 'https://plugins.gradle.org/m2/'
    }
  }
  dependencies {
    classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.8'
    classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-beta.4'
  }
}

apply plugin: 'org.asciidoctor.convert'
apply plugin: 'java'

asciidoctor {
  backends 'html5'
  attributes 'build-gradle': file('build.gradle'),
    'sourcedir': './snippets',
    'endpoint-url': 'http://example.org',
    'source-highlighter': 'coderay',
    'imagesdir': './images',
    'toc': '',
    'icons': 'font',
    'setanchors': '',
    'idprefix': '',
    'idseparator': '-',
    'docinfo1': ''
}
thekalinga commented 5 years ago

Got it!.. Will go over this

https://github.com/asciidoctor/asciidoctor-gradle-examples/tree/master/asciidoc-to-pdf-example

Thanks

thekalinga commented 5 years ago

But, most of these use <2.0.0 :(

mojavelinux commented 5 years ago

No one has stepped forward yet to update them. But yes, they are in need of updating.

You can set the version of Asciidoctor used. See https://github.com/asciidoctor/asciidoctor-maven-examples/blob/master/asciidoc-to-html-example/pom.xml#L16

thekalinga commented 5 years ago

Created a sample project with rouge highlighter with 2.3.0 version

I have couple of problems

  1. When I generate pdf, I get the source highlighted. But when I generate html, the source is not highlighted
  2. Line numbers are being highlighted when using rouge highlighter (even in pdf)

Appreciate if you can have a quick look at it

https://github.com/thekalinga/asciidoctor-2-test

mojavelinux commented 5 years ago

You're still using asciidoctorj 1.6.2. You need to be using asciidoctorj 2.1.0.

Line highlighting is not supported for rouge in Asciidoctor PDF. See https://github.com/asciidoctor/asciidoctor-pdf/issues/681

mojavelinux commented 5 years ago

You can set the version of core using the version property (next to pdf.version).

mojavelinux commented 5 years ago

The CSS is missing for the line highlighting in the HTML. If you view the source, you will see the .hll classes there.

thekalinga commented 5 years ago

Is this correct?

asciidoctorj {
  version '2.1.0'
  modules {
    pdf.version '1.5.0-beta.4'
  }
}
mojavelinux commented 5 years ago

inside modules

mojavelinux commented 5 years ago

(I guess it works either place)

mojavelinux commented 5 years ago

The line highlighting support is something that Asciidoctor adds. Rouge doesn't actually have support for highlighting lines. That's why the CSS is missing from the theme. So you have to add it yourself using a docinfo file.

thekalinga commented 5 years ago

With this, I got color in html

plugins {
  id 'org.asciidoctor.jvm.convert' version '2.3.0'
  id 'org.asciidoctor.jvm.pdf' version '2.3.0'
}

repositories {
  mavenLocal()
  jcenter()
  maven { url 'http://rubygems-proxy.torquebox.org/releases' }
  mavenCentral()
}

apply plugin: 'java'

version '1.0.0-SNAPSHOT'

asciidoctorj {
  version '2.1.0'
  modules {
    pdf.version '1.5.0-beta.4'
  }
}

And can u help me with docinfo aswell

thekalinga commented 5 years ago

Do you have some link I can follow to make thatchange

Please note that I am quite noob when it comes to asciidoctor. Sorry for asking quite basic questions

thekalinga commented 5 years ago

I pushed a new version to the sample repo. In that I tried including source from external file

Html version picks the source relative to the .adoc file properly, but not pdf version

Any idea why?

mojavelinux commented 5 years ago

You are now asking questions about the Gradle plugin. Please either asking them in the Gradle plugin project https://github.com/asciidoctor/asciidoctor-gradle-plugin or in the gitter channel http://gitter.im/asciidoctor/asciidoctorj.

thekalinga commented 5 years ago

Thanks. Did not know it existed