Skip to content

Commit

Permalink
Adding optional, convert_to_json functionality to as_json
Browse files Browse the repository at this point in the history
  • Loading branch information
respondcreate committed Nov 5, 2015
1 parent ad7769d commit 17cd764
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions textplusstuff/datastructures.py
Expand Up @@ -82,6 +82,7 @@ def as_json(self, **kwargs):
final_output_as_markdown = ""
include_content_nodes = kwargs.pop('include_content_nodes', True)
extra_context = kwargs.pop('extra_context', None)
convert_to_json = kwargs.pop('convert_to_json', True)
model_stuff_node_counter = 0
model_stuff_node_context_list = []
for node in self.nodelist:
Expand Down Expand Up @@ -109,11 +110,17 @@ def as_json(self, **kwargs):
)
})
model_stuff_node_counter += 1
return json.dumps({
dict_to_return = {
'text_as_markdown': final_output_as_markdown,
'text_as_html': final_output_as_html,
'content_nodes': model_stuff_node_context_list
})
}

to_return = dict_to_return
if convert_to_json is True:
to_return = json.dumps(dict_to_return)

return to_return

def as_plaintext(self, **kwargs):
"""
Expand Down

0 comments on commit 17cd764

Please sign in to comment.