diff --git a/plugins/views_data_export_plugin_style_export_csv.inc b/plugins/views_data_export_plugin_style_export_csv.inc
index 01f1faa..4aa900a 100644
--- a/plugins/views_data_export_plugin_style_export_csv.inc
+++ b/plugins/views_data_export_plugin_style_export_csv.inc
@@ -44,12 +44,15 @@ class views_data_export_plugin_style_export_csv extends views_data_export_plugin
'default' => TRUE,
'translatable' => FALSE,
);
+ $options['keep_html'] = array(
+ 'default' => FALSE,
+ 'translatable' => FALSE,
+ );
$options['encoding'] = array(
'default' => '',
'translatable' => FALSE,
);
-
return $options;
}
@@ -101,6 +104,11 @@ class views_data_export_plugin_style_export_csv extends views_data_export_plugin
'#title' => t('Make first row a list of column headers.'),
'#default_value' => !empty($this->options['header']),
);
+ $form['keep_html'] = array(
+ '#type' => 'checkbox',
+ '#default_value' => !empty($this->options['keep_html']),
+ '#title' => t('Keep HTML tags.'),
+ );
$form['encoding'] = array(
'#type' => 'select',
'#default_value' => !empty($this->options['encoding']) ? $this->options['encoding'] : '',
diff --git a/tests/base.test b/tests/base.test
index ec9387e..e35e554 100644
--- a/tests/base.test
+++ b/tests/base.test
@@ -481,11 +481,12 @@ abstract class ViewsDataExportSimpleExportTest extends ViewsDataExportBaseTest {
* This will take a view, and add a display plugin of the correct export type,
* and then run it and compare it with the expected output.
*/
- protected function executeAndCompareGivenView(view $view, $expected, $message = '') {
+ protected function executeAndCompareGivenView(view $view, $expected, $message = '', $style_options = array()) {
$path = 'vde_test/' . $this->randomName();
$display = $view->new_display('views_data_export', 'Data export', 'vde_test');
$display->override_option('style_plugin', $this->getStylePluginName());
+ $display->override_option('style_options', $style_options);
$display->override_option('path', $path);
// Save this view so we can hit the path.
diff --git a/tests/csv_export.test b/tests/csv_export.test
index 08238da..000bc6c 100644
--- a/tests/csv_export.test
+++ b/tests/csv_export.test
@@ -36,4 +36,73 @@ class CSVExportViewsDataExportTests extends ViewsDataExportSimpleExportTest {
return array(&$view, $expected);
}
+ /**
+ * Test to ensure that HTML tags are kept in CSV files when requested.
+ */
+ protected function testKeepHTML() {
+ $view = $this->getBasicExportView();
+
+ $display = $view->display['default']->handler;
+
+ $display->override_option('fields', array(
+ 'id' => array(
+ 'id' => 'id',
+ 'table' => 'views_test',
+ 'field' => 'id',
+ 'relationship' => 'none',
+ // Add a label to include HTML
+ 'label' => 'ID',
+ ),
+ 'name' => array(
+ 'id' => 'name',
+ 'table' => 'views_test',
+ 'field' => 'name',
+ 'relationship' => 'none',
+ // Alter this field to include HTML.
+ 'alter' => array(
+ 'alter_text' => TRUE,
+ 'text' => '[name]',
+ ),
+ ),
+ 'age' => array(
+ 'id' => 'age',
+ 'table' => 'views_test',
+ 'field' => 'age',
+ 'relationship' => 'none',
+ ),
+ ));
+
+ $style_options = array(
+ 'keep_html' => TRUE,
+ );
+
+ $expected = '"ID","Name","Age"
+"1","John","25"
+"2","George","27"
+"3","Ringo","28"
+"4","Paul","26"
+"5","Meredith","30"';
+
+ $message = 'Keep HTML test in ' . $this->vde_export_type . ' export matched expected output.';
+
+ $this->executeAndCompareGivenView($view, $expected, $message, $style_options);
+
+
+ // And now make sure that HTML tags are stripped correctly.
+ $style_options = array(
+ 'keep_html' => FALSE,
+ );
+
+ $expected = '"ID","Name","Age"
+"1","John","25"
+"2","George","27"
+"3","Ringo","28"
+"4","Paul","26"
+"5","Meredith","30"';
+
+ $message = 'Keep HTML reverse test in ' . $this->vde_export_type . ' export matched expected output.';
+
+ $this->executeAndCompareGivenView($view, $expected, $message, $style_options);
+ }
+
}
diff --git a/theme/views_data_export.theme.inc b/theme/views_data_export.theme.inc
index c2668f6..bc69cbd 100644
--- a/theme/views_data_export.theme.inc
+++ b/theme/views_data_export.theme.inc
@@ -105,7 +105,8 @@ function template_preprocess_views_data_export_csv_header(&$vars) {
// Format header values.
foreach ($vars['header'] as $key => $value) {
- $output = decode_entities(strip_tags($value));
+ $output = decode_entities($value);
+ $output = (empty($vars['options']['keep_html'])) ? strip_tags($output) : $output;
if (!empty($vars['options']['trim'])) {
$output = trim($output);
}
@@ -148,7 +149,8 @@ function template_preprocess_views_data_export_csv_body(&$vars) {
// Format row values.
foreach ($vars['themed_rows'] as $i => $values) {
foreach ($values as $j => $value) {
- $output = decode_entities(strip_tags($value));
+ $output = decode_entities($value);
+ $output = (empty($vars['options']['keep_html'])) ? strip_tags($output) : $output;
if (!empty($vars['options']['trim'])) {
$output = trim($output);
}