/*jslint browser: true*/

"use strict";

/*jshint esversion: 6 */
class tedi2md extends tedi2lang {
	constructor() {
		const td = {

			start_heading_first_level_tag:"# ",
			start_heading_second_level_tag:"## ",
			start_heading_third_level_tag:"### ",
			start_heading_fourth_level_tag:"#### ",

			end_heading_first_level_tag:"",
			end_heading_second_level_tag:"",
			end_heading_third_level_tag:"",
			end_heading_fourth_level_tag:"",

			start_list_tag:"",
			list_item_tag:"- ",
			end_list_tag:"",

			start_container_tag:"<div class=\"",
			middle_container_tag:"\">",
			end_container_tag:"</div>",

			start_link_tag:"<a href=\"",
			middle_link_tag:"\">",
			end_link_tag:"</a>",

			start_image_tag:"<img alt=\"",
			middle_image_tag:"\" src=\"",
			end_image_tag:"\">",

			start_table_tag:"<table>",
			end_table_tag:"</table>",
			start_table_row_tag:"<tr>",
			end_table_row_tag:"</tr>",
			start_table_data_tag:"<td>",
			end_table_data_tag:"</td>",

			end_paragraph_tag:"\n"
		   
		};
		super(td);
		this._start_paragraph_tag = "";
	}
	
	/*
	 * Control tags:
	 * <!, <>, <+. <
	 */
	convert_line_control_tags(line) {
		if(line[1] != '!') {
			if(line[1] == '>') {
				line = line.erase(0,2);
				return line + "\n";
			} else if(line[1] == '+') {
				line = line.erase(0,2);
				if(this._is_paragraph) {
					this._is_paragraph = false;
					return line + this._end_paragraph_tag + "\n";

				} else
					return this._start_paragraph_tag + line + this._end_paragraph_tag + "\n";
				
			} else {
				line = line.erase(0,1);
				return line + "\n";
			}
		} else
			return "";
		
	}

}
