diff --git a/core/modules/views/templates/views-view-table.html.twig b/core/modules/views/templates/views-view-table.html.twig
index fe6be75..903b059 100644
--- a/core/modules/views/templates/views-view-table.html.twig
+++ b/core/modules/views/templates/views-view-table.html.twig
@@ -72,7 +72,21 @@
             %}
           {% endif %}
           <th{{ column.attributes.addClass(column_classes).setAttribute('scope', 'col') }}>
-            {{ column.content }}
+            {%- if column.wrapper_element -%}
+              <{{ column.wrapper_element }}>
+                {%- if column.url -%}
+                  <a href="{{ column.url }}">{{ column.content }}{{ column.sort_indicator }}</a>
+                {%- else -%}
+                  {{ column.content }}{{ column.sort_indicator }}
+                {%- endif -%}
+              </{{ column.wrapper_element }}>
+            {%- else -%}
+              {%- if column.url -%}
+                <a href="{{ column.url }}">{{ column.content }}{{ column.sort_indicator }}</a>
+              {%- else -%}
+                {{- column.content }}{{ column.sort_indicator }}
+              {%- endif -%}
+            {%- endif -%}
           </th>
         {% endfor %}
       </tr>
@@ -93,7 +107,12 @@
             {% endfor %}
           {% endif %}
           <td{{ column.attributes.addClass(column_classes) }}>
-            {{ column.content }}
+            {{- column.content }}{{ column.separator -}}
+            {%- if column.wrapper_element -%}
+              <{{ column.wrapper_element }}>{{ column.field_output }}</{{ column.wrapper_element }}>
+            {%- else -%}
+              {{- column.field_output -}}
+            {%- endif %}
           </td>
         {% endfor %}
       </tr>
diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc
index 4853613..858320b 100644
--- a/core/modules/views/views.theme.inc
+++ b/core/modules/views/views.theme.inc
@@ -469,7 +469,7 @@ function template_preprocess_views_view_table(&$variables) {
 
     // Render the header labels.
     if ($field == $column && empty($fields[$field]->options['exclude'])) {
-      $label = SafeMarkup::checkPlain(!empty($fields[$field]) ? $fields[$field]->label() : '');
+      $label = !empty($fields[$field]) ? $fields[$field]->label() : '';
       if (empty($options['info'][$field]['sortable']) || !$fields[$field]->clickSortable()) {
         $variables['header'][$field]['content'] = $label;
       }
@@ -482,12 +482,10 @@ function template_preprocess_views_view_table(&$variables) {
 
         $title = t('sort by @s', array('@s' => $label));
         if ($active == $field) {
-          $tablesort_indicator = array(
+          $variables['header'][$field]['sort_indicator'] = array(
             '#theme' => 'tablesort_indicator',
             '#style' => $initial,
           );
-          $markup = drupal_render($tablesort_indicator);
-          $label = SafeMarkup::set($label . $markup);
         }
 
         $query['order'] = $field;
@@ -498,7 +496,9 @@ function template_preprocess_views_view_table(&$variables) {
         );
         // It is ok to specify no URL path here as we will always reload the
         // current page.
-        $variables['header'][$field]['content'] = \Drupal::l($label, new Url('<none>', [], $link_options));
+        $url = new Url('<none>', [], $link_options);
+        $variables['header'][$field]['url'] = $url->toString();
+        $variables['header'][$field]['content'] = $label;
       }
 
       $variables['header'][$field]['default_classes'] = $fields[$field]->options['element_default_classes'];
@@ -521,7 +521,7 @@ function template_preprocess_views_view_table(&$variables) {
       if ($variables['header'][$field]['content']) {
         $element_label_type = $fields[$field]->elementLabelType(TRUE, TRUE);
         if ($element_label_type) {
-          $variables['header'][$field]['content'] = '<' . $element_label_type . '>' . $variables['header'][$field]['content'] . '</' . $element_label_type . '>';
+          $variables['header'][$field]['wrapper_element'] = $element_label_type;
         }
         // Improves accessibility of complex tables.
         $variables['header'][$field]['attributes']['id'] = Html::getUniqueId('view-' . $field . '-table-column');
@@ -578,27 +578,13 @@ function template_preprocess_views_view_table(&$variables) {
 
       if (!empty($fields[$field])) {
         $field_output = $handler->getField($num, $field);
-        $element_type = $fields[$field]->elementType(TRUE, TRUE);
-        if ($element_type) {
-          $field_output = SafeMarkup::set('<' . $element_type . '>' .  SafeMarkup::escape($field_output) . '</' . $element_type . '>');
-        }
+        $column_reference['wrapper_element'] = $fields[$field]->elementType(TRUE, TRUE);
 
+        $column_reference['field_output'][] = ['#markup' => $field_output];
         // Only bother with separators and stuff if the field shows up.
-        if (!empty($field_output)) {
-          // Place the field into the column, along with an optional separator.
-          if (!empty($column_reference['content'])) {
-            if (!empty($options['info'][$column]['separator'])) {
-              $safe_content = SafeMarkup::escape($column_reference['content']);
-              $safe_separator = Xss::filterAdmin($options['info'][$column]['separator']);
-              $column_reference['content'] = SafeMarkup::set($safe_content . $safe_separator);
-            }
-          }
-          else {
-            $column_reference['content'] = '';
-          }
-          $safe_content = SafeMarkup::escape($column_reference['content']);
-          $safe_field_output = SafeMarkup::escape($field_output);
-          $column_reference['content'] = SafeMarkup::set($safe_content . $safe_field_output);
+        // Place the field into the column, along with an optional separator.
+        if (!empty($field_output) && !empty($column_reference['content']) && !empty($options['info'][$column]['separator'])) {
+          $column_reference['field_output'][] = ['#markup' => $options['info'][$column]['separator']];
         }
       }
       $column_reference['attributes'] = new Attribute($column_reference['attributes']);
@@ -635,7 +621,7 @@ function template_preprocess_views_view_table(&$variables) {
 
   if (empty($variables['rows']) && !empty($options['empty_table'])) {
     $build = $view->display_handler->renderArea('empty');
-    $variables['rows'][0]['columns'][0]['content'] = drupal_render($build);
+    $variables['rows'][0]['columns'][0]['content'] = $build;
     $variables['rows'][0]['attributes'] = new Attribute(array('class' => 'odd'));
     // Calculate the amounts of rows with output.
     $variables['rows'][0]['columns'][0]['attributes'] = new Attribute(array(
@@ -652,7 +638,7 @@ function template_preprocess_views_view_table(&$variables) {
 
   // Add the caption to the list if set.
   if (!empty($handler->options['caption'])) {
-    $variables['caption'] = Xss::filterAdmin($handler->options['caption']);
+    $variables['caption'] = ['#markup' => $handler->options['caption']];
     $variables['caption_needed'] = TRUE;
   }
   else {
diff --git a/core/themes/classy/templates/views/views-view-table.html.twig b/core/themes/classy/templates/views/views-view-table.html.twig
index 08fefd4..067d5ba 100644
--- a/core/themes/classy/templates/views/views-view-table.html.twig
+++ b/core/themes/classy/templates/views/views-view-table.html.twig
@@ -72,7 +72,21 @@
             %}
           {% endif %}
           <th{{ column.attributes.addClass(column_classes).setAttribute('scope', 'col') }}>
-            {{ column.content }}
+            {%- if column.wrapper_element -%}
+              <{{ column.wrapper_element }}>
+                {%- if column.url -%}
+                  <a href="{{ column.url }}">{{ column.content }}{{ column.sort_indicator }}</a>
+                {%- else -%}
+                  {{ column.content }}{{ column.sort_indicator }}
+                {%- endif -%}
+              </{{ column.wrapper_element }}>
+            {%- else -%}
+              {%- if column.url -%}
+                <a href="{{ column.url }}">{{ column.content }}{{ column.sort_indicator }}</a>
+              {%- else -%}
+                {{- column.content }}{{ column.sort_indicator }}
+              {%- endif -%}
+            {%- endif -%}
           </th>
         {% endfor %}
       </tr>
@@ -93,7 +107,12 @@
             {% endfor %}
           {% endif %}
           <td{{ column.attributes.addClass(column_classes) }}>
-            {{ column.content }}
+            {{- column.content }}{{ column.separator -}}
+            {%- if column.wrapper_element -%}
+              <{{ column.wrapper_element }}>{{ column.field_output }}</{{ column.wrapper_element }}>
+            {%- else -%}
+              {{- column.field_output -}}
+            {%- endif %}
           </td>
         {% endfor %}
       </tr>
