Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Hugo Hörnquist
Guile Gumbo
Commits
0098709f
Commit
0098709f
authored
Jul 02, 2020
by
Hugo Hörnquist
Browse files
Cleanup and options.
parent
52180eff
Changes
5
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
0098709f
.PHONY
:
all install
CFLAGS
=
-Wall
$(
shell
pkg-config
--cflags
gumbo
)
$(
shell
guile-config compile
)
CFLAGS
=
-Wall
-pedantic
$(
shell
pkg-config
--cflags
gumbo
)
$(
shell
guile-config compile
)
LDLIBS
=
$(
shell
pkg-config
--libs
gumbo
)
$(
shell
guile-config
link
)
GUILE_SITE_DIR
=
$(
shell
guile
-c
"(display (%site-dir
))
"
)
...
...
@@ -9,7 +9,7 @@ GUILE_CCACHE_DIR=$(shell guile -c "(display (%site-ccache-dir))")
TARGET
=
libguile-gumbo.so
DESTDIR
=
all
:
${TARGET}
gumbo
.go
all
:
${TARGET}
html
.go
guile-gumbo.o
:
guile-gumbo.x
...
...
@@ -26,8 +26,8 @@ ${TARGET}: guile-gumbo.o
$(CC)
-shared
-o
$@
-fPIC
$^
$(LDLIBS)
install
:
all
install
-m
644
-Dt
${DESTDIR}${GUILE_
CCACH
E_DIR}
/sxml/
gumbo.go
install
-m
644
-Dt
${DESTDIR}${GUILE_
SIT
E_DIR}
/sxml/
gumbo.scm
install
-m
644
-Dt
${DESTDIR}${GUILE_
SIT
E_DIR}
/sxml/
html.scm
install
-m
644
-Dt
${DESTDIR}${GUILE_
CCACH
E_DIR}
/sxml/
html.go
install
-Dt
${DESTDIR}
/usr/lib/ libguile-gumbo.so
clean
:
...
...
README.md
View file @
0098709f
...
...
@@ -12,5 +12,5 @@ Example:
(html->sxml "Hello")
⇒ (*TOP* (html (head) (body "Hello")))
(html->sxml "<!doctype html><title>Minimum valid document</title>")
⇒ (*TOP* (
*PI* "
html
"
) (html (head (title "Minimum valid document")) (body)))
⇒ (*TOP* (
doctype
html) (html (head (title "Minimum valid document")) (body)))
guile-gumbo.c
View file @
0098709f
#include <gumbo.h>
#include <libguile.h>
#include <stdbool.h>
typedef
struct
options
{
int
trim_whitespace
;
bool
trim_whitespace
;
bool
full_document
;
/* should the *TOP* and doctype nodes be included? */
}
options
;
/*
...
...
@@ -25,8 +27,8 @@ static SCM scm_parse_children (GumboVector* /* GumboNode*/, options*);
body; \
}
SCM_DEFINE_PUBLIC
(
scm_parse_html
,
"parse-html"
,
1
,
0
,
0
,
(
SCM
string
),
SCM_DEFINE_PUBLIC
(
scm_parse_html
,
"parse-html"
,
2
,
0
,
0
,
(
SCM
string
,
SCM
options_assq
),
""
)
#define FUNC_NAME s_scm_parse_html
{
...
...
@@ -35,14 +37,17 @@ SCM_DEFINE_PUBLIC (scm_parse_html, "parse-html", 1, 0, 0,
GumboOutput
*
output
=
gumbo_parse
(
str
);
/* TODO this doesn't seem to do anything.
* Also, it should be passed as a parameter
*/
options
opts
=
{
.
trim_whitespace
=
0
.
trim_whitespace
=
scm_to_bool
(
scm_assq_ref
(
options_assq
,
scm_from_utf8_symbol
(
"trim-whitespace?"
))),
.
full_document
=
scm_to_bool
(
scm_assq_ref
(
options_assq
,
scm_from_utf8_symbol
(
"full-document?"
))),
};
SCM
retval
=
parse_tree
(
output
->
document
,
&
opts
);
SCM
retval
;
if
(
opts
.
full_document
)
{
retval
=
parse_tree
(
output
->
document
,
&
opts
);
}
else
{
retval
=
parse_tree
(
output
->
root
,
&
opts
);
}
gumbo_destroy_output
(
&
kGumboDefaultOptions
,
output
);
...
...
@@ -112,8 +117,8 @@ SCM parse_tree (GumboNode* node, options* options) {
SCM
document
=
scm_parse_children
(
&
doc
->
children
,
options
);
if
(
doc
->
has_doctype
)
{
SCM
lst
=
SCM_EOL
;
lst
=
scm_cons
(
scm_from_utf8_symbol
(
"
*PI*
"
),
lst
);
SCM
name
=
scm_from_utf8_stringn
(
doc
->
name
,
strlen
(
doc
->
name
));
lst
=
scm_cons
(
scm_from_utf8_symbol
(
"
doctype
"
),
lst
);
SCM
name
=
scm_string_to_symbol
(
scm_from_utf8_stringn
(
doc
->
name
,
strlen
(
doc
->
name
))
)
;
lst
=
scm_cons
(
name
,
lst
);
if
(
*
doc
->
public_identifier
!=
'\0'
)
{
lst
=
scm_cons
(
scm_c_concat
(
"public_identifier="
,
doc
->
public_identifier
),
lst
);
...
...
gumbo.scm
deleted
100644 → 0
View file @
52180eff
(
define-module
(
sxml
gumbo
)
;; rename to allow future wrapper with handling of optional
;; arguments.
#
:export
((
parse-html
.
html->sxml
)))
(
load-extension
"libguile-gumbo"
"scm_init_gumbo"
)
html.scm
0 → 100644
View file @
0098709f
(
define-module
(
sxml
html
)
#
:export
(
html->sxml
))
(
load-extension
"libguile-gumbo"
"scm_init_gumbo"
)
(
define*
(
html->sxml
str
#
:key
(
trim-whitespace?
#t
)
(
full-document?
#t
))
(
parse-html
str
`
((
trim-whitespace?
.
,
trim-whitespace?
)
(
full-document?
.
,
full-document?
))))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment