BEGIN {
$Org::Dump::VERSION
=
'0.07'
;
}
use
5.010;
sub
dump_element {
my
(
$el
,
$indent_level
) =
@_
;
$indent_level
//= 0;
my
@res
;
my
$line
=
" "
x
$indent_level
;
my
$type
=
ref
(
$el
);
$type
=~ s/^Org::(?:Element::)?//;
$line
.=
"$type:"
;
if
(
$type
eq
'Headline'
) {
$line
.=
" l="
.
$el
->level;
$line
.=
" tags "
.
join
(
","
, @{
$el
->tags})
if
$el
->tags;
$line
.=
" todo="
.
$el
->todo_state
if
$el
->todo_state;
}
elsif
(
$type
eq
'Footnote'
) {
$line
.=
" name="
.(
$el
->name //
""
);
}
elsif
(
$type
eq
'List'
) {
$line
.=
" "
.
$el
->type;
$line
.=
"("
.
$el
->bullet_style.
")"
;
$line
.=
" indent="
.
length
(
$el
->indent);
}
elsif
(
$type
eq
'ListItem'
) {
$line
.=
" "
.
$el
->bullet;
$line
.=
" ["
.
$el
->check_state.
"]"
if
$el
->check_state;
}
elsif
(
$type
eq
'Text'
) {
$line
.=
" "
.
$el
->style
if
$el
->style;
}
elsif
(
$type
eq
'Timestamp'
) {
$line
.=
" A"
if
$el
->is_active;
$line
.=
" dt="
.
$el
->datetime;
}
elsif
(
$type
eq
'TimeRange'
) {
}
elsif
(
$type
eq
'Drawer'
) {
$line
.=
" "
.
$el
->name;
$line
.=
" "
._format_properties(
$el
->properties)
if
$el
->name eq
'PROPERTIES'
&&
$el
->properties;
}
unless
(
$el
->children) {
$line
.=
" \""
.
printable(elide((
$el
->_str //
$el
->as_string), 50)).
"\""
;
}
push
@res
,
$line
,
"\n"
;
if
(
$type
eq
'Headline'
) {
push
@res
,
" "
x (
$indent_level
+1),
"(title)\n"
;
push
@res
, dump_element(
$el
->title,
$indent_level
+1);
push
@res
,
" "
x (
$indent_level
+1),
"(children)\n"
if
$el
->children;
}
elsif
(
$type
eq
'Footnote'
) {
if
(
$el
->def) {
push
@res
,
" "
x (
$indent_level
+1),
"(definition)\n"
;
push
@res
, dump_element(
$el
->def,
$indent_level
+1);
}
push
@res
,
" "
x (
$indent_level
+1),
"(children)\n"
if
$el
->children;
}
elsif
(
$type
eq
'ListItem'
) {
if
(
$el
->desc_term) {
push
@res
,
" "
x (
$indent_level
+1),
"(description term)\n"
;
push
@res
, dump_element(
$el
->desc_term,
$indent_level
+1);
}
push
@res
,
" "
x (
$indent_level
+1),
"(children)\n"
if
$el
->children;
}
if
(
$el
->children) {
push
@res
, dump_element(
$_
,
$indent_level
+1)
for
@{
$el
->children };
}
join
""
,
@res
;
}
sub
_format_properties {
my
(
$props
) =
@_
;
my
@s
;
for
my
$k
(
sort
keys
%$props
) {
my
$v
=
$props
->{
$k
};
if
(
ref
(
$v
) eq
'ARRAY'
) {
$v
=
"["
.
join
(
","
,
map
{printable(
$_
)}
@$v
).
"]"
;
}
else
{
$v
= printable(
$v
);
}
push
@s
,
"$k=$v"
;
}
"{"
.
join
(
", "
,
@s
) .
"}"
;
}
1;