diff --git a/h-m-m b/h-m-m
index c6c5a4c..8417dab 100755
--- a/h-m-m
+++ b/h-m-m
@@ -829,10 +829,6 @@ function build_map(&$mm)
calculate_y($mm);
calculate_height_shift($mm, $mm['root']);
- // in case it was resized!
- $mm['terminal_width'] = exec('tput cols');
- $mm['terminal_height'] = exec('tput lines');
-
// resetting the map, 2/2
$height = max($mm['map_bottom'],$mm['terminal_height']);
$blank = str_repeat(' ', $mm['map_width']+$mm['terminal_width']);
@@ -1383,6 +1379,109 @@ function move_active_node_up(&$mm)
+// }}}
+// {{{ export html
+
+function export_html(&$mm)
+{
+
+ if (empty($mm['filename']))
+ {
+ message($mm, "Can't export the map when it doesn't have a file name yet. Save it first.");
+ return;
+ }
+
+ $file = fopen($mm['filename'].'.html', "w");
+
+ if ($file===false)
+ {
+ message($mm, 'ERROR! Could not save the file');
+ return;
+ }
+
+
+ fwrite
+ (
+ $file
+ ,''
+ .''
+ .'
'
+ .''
+ .''
+ .''
+ .''
+ .export_html_node($mm, $mm['root'])
+ .'
'
+ .''
+ .'This is a limited, read-only version of a mind-map created in h-m-m | view source!
'
+ .''
+ .encode_tree($mm,$mm['root'])
+ .'
'
+ .' '
+ .''
+ .''
+ );
+
+ fclose($file);
+
+ message($mm, 'Exported as '.$mm['filename'].'.html');
+
+}
+
+
+function export_html_node(&$mm, $parent_id)
+{
+ if ($mm['nodes'][$parent_id]['children']==[])
+ {
+ $output =
+ ""
+ .$mm['nodes'][$parent_id]['title']
+ ."
";
+ }
+ elseif ($parent_id==$mm['root'])
+ {
+ $output =
+ ""
+ .$mm['nodes'][$parent_id]['title']
+ ."
";
+
+ foreach ($mm['nodes'][$parent_id]['children'] as $cid)
+ $output .= export_html_node($mm, $cid);
+ }
+ else
+ {
+ $output =
+ ""
+ .""
+ .$mm['nodes'][$parent_id]['title']
+ ."
";
+
+ foreach ($mm['nodes'][$parent_id]['children'] as $cid)
+ $output .= export_html_node($mm, $cid);
+
+ $output .=
+ " ";
+ }
+
+ return $output;
+}
+
+
+
// }}}
// {{{ save
@@ -2186,6 +2285,8 @@ function monitor_key_presses(&$mm)
case 'n': next_search_result($mm); break;
case 'N': previous_search_result($mm); break;
+ case 'x': export_html($mm); break;
+
case 's': save($mm); break;
case 'S': save($mm, true); break;
diff --git a/readme.md b/readme.md
index a3a5c0e..3a4b4b6 100644
--- a/readme.md
+++ b/readme.md
@@ -58,10 +58,11 @@ Search:
* `n` - goes to the next search result
* `N` - goes to the previous search result
-Save and quit:
+Save, export, and quit:
* `s` - saves with the previous file name (or asks for one if there's none)
* `S` - saves with a new file name
+* `x` - export as HTML
* `q` - quits (if the changes were already saved)
* `Q` - quits, ignoring the changes