-
Notifications
You must be signed in to change notification settings - Fork 3
/
documentend.go
47 lines (42 loc) · 1.31 KB
/
documentend.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package lolhtml
/*
#include <stdlib.h>
#include "lol_html.h"
*/
import "C"
import "unsafe"
// DocumentEnd represents the end of the document.
type DocumentEnd C.lol_html_doc_end_t
// DocumentEndHandlerFunc is a callback handler function to do something with a DocumentEnd.
type DocumentEndHandlerFunc func(*DocumentEnd) RewriterDirective
// AppendAsText appends the given content at the end of the document.
//
// The rewriter will HTML-escape the content before appending:
//
// `<` will be replaced with `<`
//
// `>` will be replaced with `>`
//
// `&` will be replaced with `&`
func (d *DocumentEnd) AppendAsText(content string) error {
contentC := C.CString(content)
defer C.free(unsafe.Pointer(contentC))
contentLen := len(content)
errCode := C.lol_html_doc_end_append((*C.lol_html_doc_end_t)(d), contentC, C.size_t(contentLen), false)
if errCode == 0 {
return nil
}
return getError()
}
// AppendAsHTML appends the given content at the end of the document.
// The content is appended as is.
func (d *DocumentEnd) AppendAsHTML(content string) error {
contentC := C.CString(content)
defer C.free(unsafe.Pointer(contentC))
contentLen := len(content)
errCode := C.lol_html_doc_end_append((*C.lol_html_doc_end_t)(d), contentC, C.size_t(contentLen), true)
if errCode == 0 {
return nil
}
return getError()
}