Skip to content

Upgrade hoedown to 3.0.4 #27945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Aug 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 46 additions & 36 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
//! // ... something using html
//! ```

#![allow(dead_code)]
#![allow(non_camel_case_types)]

use libc;
Expand All @@ -51,7 +50,7 @@ pub struct Markdown<'a>(pub &'a str);
pub struct MarkdownWithToc<'a>(pub &'a str);

const DEF_OUNIT: libc::size_t = 64;
const HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 10;
const HOEDOWN_EXT_NO_INTRA_EMPHASIS: libc::c_uint = 1 << 11;
const HOEDOWN_EXT_TABLES: libc::c_uint = 1 << 0;
const HOEDOWN_EXT_FENCED_CODE: libc::c_uint = 1 << 1;
const HOEDOWN_EXT_AUTOLINK: libc::c_uint = 1 << 3;
Expand All @@ -65,52 +64,63 @@ const HOEDOWN_EXTENSIONS: libc::c_uint =
HOEDOWN_EXT_STRIKETHROUGH | HOEDOWN_EXT_SUPERSCRIPT |
HOEDOWN_EXT_FOOTNOTES;

type hoedown_document = libc::c_void; // this is opaque to us
enum hoedown_document {}

type blockcodefn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*const hoedown_buffer, *mut libc::c_void);
*const hoedown_buffer, *const hoedown_renderer_data);

type blockquotefn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*const hoedown_renderer_data);

type headerfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
libc::c_int, *mut libc::c_void);
libc::c_int, *const hoedown_renderer_data);

type blockhtmlfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*const hoedown_renderer_data);

type codespanfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*mut libc::c_void) -> libc::c_int;
*const hoedown_renderer_data) -> libc::c_int;

type linkfn = extern "C" fn (*mut hoedown_buffer, *const hoedown_buffer,
*const hoedown_buffer, *const hoedown_buffer,
*mut libc::c_void) -> libc::c_int;
*const hoedown_renderer_data) -> libc::c_int;

type entityfn = extern "C" fn (*mut hoedown_buffer, *const hoedown_buffer,
*const hoedown_renderer_data);

type normaltextfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*mut libc::c_void);
*const hoedown_renderer_data);

#[repr(C)]
struct hoedown_renderer_data {
opaque: *mut libc::c_void,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opaque should probably also be an empty enum, but that might be more work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a void * in the C code as well, so I think this is fine (or even more appropriate, since pointers to empty enums aren't represented as *i8 in LLVM, while *mut c_void is).

}

#[repr(C)]
struct hoedown_renderer {
opaque: *mut libc::c_void,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


blockcode: Option<blockcodefn>,
blockquote: Option<extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*mut libc::c_void)>,
blockhtml: Option<extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*mut libc::c_void)>,
blockquote: Option<blockquotefn>,
header: Option<headerfn>,
other_block_level_callbacks: [libc::size_t; 9],

other_block_level_callbacks: [libc::size_t; 11],

blockhtml: Option<blockhtmlfn>,

/* span level callbacks - NULL or return 0 prints the span verbatim */
autolink: libc::size_t, // unused
codespan: Option<codespanfn>,
other_span_level_callbacks_1: [libc::size_t; 7],
link: Option<linkfn>,
other_span_level_callbacks_2: [libc::size_t; 5],
// hoedown will add `math` callback here, but we use an old version of it.
other_span_level_callbacks_2: [libc::size_t; 6],

/* low level callbacks - NULL copies input directly into the output */
entity: Option<extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*mut libc::c_void)>,
entity: Option<entityfn>,
normal_text: Option<normaltextfn>,

/* header and footer */
doc_header: Option<extern "C" fn(*mut hoedown_buffer, *mut libc::c_void)>,
doc_footer: Option<extern "C" fn(*mut hoedown_buffer, *mut libc::c_void)>,
other_callbacks: [libc::size_t; 2],
}

#[repr(C)]
Expand All @@ -120,7 +130,7 @@ struct hoedown_html_renderer_state {
flags: libc::c_uint,
link_attributes: Option<extern "C" fn(*mut hoedown_buffer,
*const hoedown_buffer,
*mut libc::c_void)>,
*const hoedown_renderer_data)>,
}

#[repr(C)]
Expand All @@ -133,7 +143,7 @@ struct html_toc_data {

struct MyOpaque {
dfltblk: extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
*const hoedown_buffer, *mut libc::c_void),
*const hoedown_buffer, *const hoedown_renderer_data),
toc_builder: Option<TocBuilder>,
}

Expand All @@ -153,7 +163,7 @@ extern {
-> *mut hoedown_renderer;
fn hoedown_html_renderer_free(renderer: *mut hoedown_renderer);

fn hoedown_document_new(rndr: *mut hoedown_renderer,
fn hoedown_document_new(rndr: *const hoedown_renderer,
extensions: libc::c_uint,
max_nesting: libc::size_t) -> *mut hoedown_document;
fn hoedown_document_render(doc: *mut hoedown_document,
Expand Down Expand Up @@ -212,11 +222,11 @@ thread_local!(pub static PLAYGROUND_KRATE: RefCell<Option<Option<String>>> = {

pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
extern fn block(ob: *mut hoedown_buffer, orig_text: *const hoedown_buffer,
lang: *const hoedown_buffer, opaque: *mut libc::c_void) {
lang: *const hoedown_buffer, data: *const hoedown_renderer_data) {
unsafe {
if orig_text.is_null() { return }

let opaque = opaque as *mut hoedown_html_renderer_state;
let opaque = (*data).opaque as *mut hoedown_html_renderer_state;
let my_opaque: &MyOpaque = &*((*opaque).opaque as *const MyOpaque);
let text = (*orig_text).as_bytes();
let origtext = str::from_utf8(text).unwrap();
Expand All @@ -228,7 +238,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
let rlang = str::from_utf8(rlang).unwrap();
if !LangString::parse(rlang).rust {
(my_opaque.dfltblk)(ob, orig_text, lang,
opaque as *mut libc::c_void);
opaque as *const hoedown_renderer_data);
true
} else {
false
Expand Down Expand Up @@ -261,7 +271,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
}

extern fn header(ob: *mut hoedown_buffer, text: *const hoedown_buffer,
level: libc::c_int, opaque: *mut libc::c_void) {
level: libc::c_int, data: *const hoedown_renderer_data) {
// hoedown does this, we may as well too
unsafe { hoedown_buffer_puts(ob, "\n\0".as_ptr() as *const _); }

Expand All @@ -280,7 +290,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
// This is a terrible hack working around how hoedown gives us rendered
// html for text rather than the raw text.

let opaque = opaque as *mut hoedown_html_renderer_state;
let opaque = unsafe { (*data).opaque as *mut hoedown_html_renderer_state };
let opaque = unsafe { &mut *((*opaque).opaque as *mut MyOpaque) };

// Make sure our hyphenated ID is unique for this page
Expand Down Expand Up @@ -320,7 +330,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
extern fn codespan(
ob: *mut hoedown_buffer,
text: *const hoedown_buffer,
_: *mut libc::c_void,
_: *const hoedown_renderer_data,
) -> libc::c_int {
let content = if text.is_null() {
"".to_string()
Expand Down Expand Up @@ -375,7 +385,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
extern fn block(_ob: *mut hoedown_buffer,
text: *const hoedown_buffer,
lang: *const hoedown_buffer,
opaque: *mut libc::c_void) {
data: *const hoedown_renderer_data) {
unsafe {
if text.is_null() { return }
let block_info = if lang.is_null() {
Expand All @@ -387,7 +397,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
};
if !block_info.rust { return }
let text = (*text).as_bytes();
let opaque = opaque as *mut hoedown_html_renderer_state;
let opaque = (*data).opaque as *mut hoedown_html_renderer_state;
let tests = &mut *((*opaque).opaque as *mut ::test::Collector);
let text = str::from_utf8(text).unwrap();
let lines = text.lines().map(|l| {
Expand All @@ -402,9 +412,9 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {

extern fn header(_ob: *mut hoedown_buffer,
text: *const hoedown_buffer,
level: libc::c_int, opaque: *mut libc::c_void) {
level: libc::c_int, data: *const hoedown_renderer_data) {
unsafe {
let opaque = opaque as *mut hoedown_html_renderer_state;
let opaque = (*data).opaque as *mut hoedown_html_renderer_state;
let tests = &mut *((*opaque).opaque as *mut ::test::Collector);
if text.is_null() {
tests.register_header("", level as u32);
Expand Down Expand Up @@ -514,11 +524,11 @@ pub fn plain_summary_line(md: &str) -> String {
_link: *const hoedown_buffer,
_title: *const hoedown_buffer,
content: *const hoedown_buffer,
opaque: *mut libc::c_void) -> libc::c_int
data: *const hoedown_renderer_data) -> libc::c_int
{
unsafe {
if !content.is_null() && (*content).size > 0 {
let ob = opaque as *mut hoedown_buffer;
let ob = (*data).opaque as *mut hoedown_buffer;
hoedown_buffer_put(ob, (*content).data as *const libc::c_char,
(*content).size);
}
Expand All @@ -528,10 +538,10 @@ pub fn plain_summary_line(md: &str) -> String {

extern fn normal_text(_ob: *mut hoedown_buffer,
text: *const hoedown_buffer,
opaque: *mut libc::c_void)
data: *const hoedown_renderer_data)
{
unsafe {
let ob = opaque as *mut hoedown_buffer;
let ob = (*data).opaque as *mut hoedown_buffer;
hoedown_buffer_put(ob, (*text).data as *const libc::c_char,
(*text).size);
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/rustdoc/issue-27862.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.


/// Test | Table
/// ------|-------------
/// t = b | id = \|x\| x
pub struct Foo; // @has issue_27862/struct.Foo.html //td 'id = |x| x'