Embedding code in a blog post
This WP installation uses the WP Geshi Highlight plugin.NOTE: a user must have the Editor role in order for this plugin to work – if the user’s role is Author, the above plugin will automatically strip attributes from the <pre> tag when the blog post is saved.
Samples
XML
No root node works ok:io.specto
hoverfly-junit
0.1.1
With some line numbers:io.specto
hoverfly-junit
0.1.1
With the XML escaped:<groupId>io.specto</groupId>
<artifactId>hoverfly-junit</artifactId>
<version>0.1.1</version<
Java
Java:public class HoverflyRuleTest {
@ClassRule
public static HoverflyRule hoverflyRule = HoverflyRule.buildFromClassPathResource(“test-service.json”).build();
private RestTemplate restTemplate;
@Before
public void setUp() {
restTemplate = new RestTemplate();
}
@Test
public void shouldBeAbleToMakeABooking() throws URISyntaxException {
// Given
final RequestEntity bookFlightRequest = RequestEntity.post(new URI(“http://www.my-test.com/api/bookings”))
.contentType(APPLICATION_JSON)
.body(“{“flightId”: “1”}”);
// When
final ResponseEntity bookFlightResponse = restTemplate.exchange(bookFlightRequest, String.class);
// Then
assertThat(bookFlightResponse.getStatusCode()).isEqualTo(CREATED);
assertThat(bookFlightResponse.getHeaders().getLocation()).isEqualTo(new URI(“http://localhost/api/bookings/1”));
}
}
With line numbers:public class HoverflyRuleTest {
@ClassRule
public static HoverflyRule hoverflyRule = HoverflyRule.buildFromClassPathResource(“test-service.json”).build();
private RestTemplate restTemplate;
@Before
public void setUp() {
restTemplate = new RestTemplate();
}
@Test
public void shouldBeAbleToMakeABooking() throws URISyntaxException {
// Given
final RequestEntity bookFlightRequest = RequestEntity.post(new URI(“http://www.my-test.com/api/bookings”))
.contentType(APPLICATION_JSON)
.body(“{“flightId”: “1”}”);
// When
final ResponseEntity bookFlightResponse = restTemplate.exchange(bookFlightRequest, String.class);
// Then
assertThat(bookFlightResponse.getStatusCode()).isEqualTo(CREATED);
assertThat(bookFlightResponse.getHeaders().getLocation()).isEqualTo(new URI(“http://localhost/api/bookings/1”));
}
}
HTML
Just set the lang
to xml
:
some text
Kotlin
Kotlin is a language that does not currently have syntax highlighting from the plugin we are using.So we need to give the <pre>
element a lang
attribute – even though kotlin
is not yet supported as a language, we might as well specify it anyway, as it will likely be included at a later date:// Kotlin
fun main(args: Array) {
println(“Hello, World!”)
}
This blog is written exclusively by the OpenCredo team. We do not accept external contributions.