ext/nokogumbo/nokogumbo.c in nokogumbo-2.0.0 vs ext/nokogumbo/nokogumbo.c in nokogumbo-2.0.1
- old
+ new
@@ -383,11 +383,11 @@
case GUMBO_NODE_TEMPLATE:
// XXX: Should create a template element and a new DocumentFragment
case GUMBO_NODE_ELEMENT:
{
xml_child = xmlNewDocNode(doc, NIL, BAD_CAST gumbo_child->v.element.name, NULL);
- set_line(xml_child, gumbo_child->v.text.start_pos.line);
+ set_line(xml_child, gumbo_child->v.element.start_pos.line);
if (xml_root == NIL)
xml_root = xml_child;
xmlNsPtr ns = NIL;
switch (gumbo_child->v.element.tag_namespace) {
case GUMBO_NAMESPACE_HTML:
@@ -707,14 +707,16 @@
return Qnil;
}
// Initialize the Nokogumbo class and fetch constants we will use later.
void Init_nokogumbo() {
- rb_funcall(rb_mKernel, rb_intern("gem"), 1, rb_utf8_str_new_static("nokogiri", 8));
+ rb_funcall(rb_mKernel, rb_intern_const("gem"), 1, rb_utf8_str_new_static("nokogiri", 8));
rb_require("nokogiri");
-#ifndef NGLIB
+ VALUE line_supported = Qtrue;
+
+#if !NGLIB
// Class constants.
VALUE mNokogiri = rb_const_get(rb_cObject, rb_intern_const("Nokogiri"));
VALUE mNokogiriXml = rb_const_get(mNokogiri, rb_intern_const("XML"));
cNokogiriXmlSyntaxError = rb_const_get(mNokogiriXml, rb_intern_const("SyntaxError"));
cNokogiriXmlElement = rb_const_get(mNokogiriXml, rb_intern_const("Element"));
@@ -723,10 +725,13 @@
cNokogiriXmlComment = rb_const_get(mNokogiriXml, rb_intern_const("Comment"));
// Interned symbols.
new = rb_intern_const("new");
node_name_ = rb_intern_const("node_name=");
+
+ // #line is not supported (returns 0)
+ line_supported = Qfalse;
#endif
// Class constants.
VALUE HTML5 = rb_const_get(mNokogiri, rb_intern_const("HTML5"));
Document = rb_const_get(HTML5, rb_intern_const("Document"));
@@ -737,8 +742,13 @@
// Define Nokogumbo module with parse and fragment methods.
VALUE Gumbo = rb_define_module("Nokogumbo");
rb_define_singleton_method(Gumbo, "parse", parse, 4);
rb_define_singleton_method(Gumbo, "fragment", fragment, 5);
+
+ // Add private constant for testing.
+ rb_define_const(Gumbo, "LINE_SUPPORTED", line_supported);
+ rb_funcall(Gumbo, rb_intern_const("private_constant"), 1,
+ rb_utf8_str_new_cstr("LINE_SUPPORTED"));
}
// vim: set shiftwidth=2 softtabstop=2 tabstop=8 expandtab: